Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to read .info/serverTimeOffset #665

Open
2 of 3 tasks
rvalitov opened this issue Oct 27, 2021 · 5 comments
Open
2 of 3 tasks

Error when trying to read .info/serverTimeOffset #665

rvalitov opened this issue Oct 27, 2021 · 5 comments

Comments

@rvalitov
Copy link

rvalitov commented Oct 27, 2021

Describe the issue you are experiencing

I want to read the serverTimeOffset to understand the difference in time between the local server and Firebase hosting.

$timeOffset = $database->getReference(".info/serverTimeOffset")->getValue();

I get error:

In Database.php line 43:
The child key ".info" contains one of the following invalid characters: ".$#[]"
In Validator.php line 66:
The child key ".info" contains one of the following invalid characters: ".$#[]"

Is there any way to read the time offset?

Installed packages

barryvdh/laravel-dompdf            v0.9.0  A DOMPDF Wrapper for Laravel
brick/math                         0.9.3   Arbitrary-precision arithmetic library
chillerlan/php-qrcode              4.3.1   A QR code generator. PHP 7.4+
chillerlan/php-settings-container  2.1.2   A container class for immutable settings objects. Not a DI container. PHP 7.4+
doctrine/inflector                 2.0.3   PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator              1.4.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                     1.2.1   PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
dompdf/dompdf                      v1.0.2  DOMPDF is a CSS 2.1 compliant HTML to PDF converter
dragonmantank/cron-expression      v3.1.0  CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
egulias/email-validator            2.1.25  A library for validating emails against several RFCs
fakerphp/faker                     v1.16.0 Faker is a PHP library that generates fake data for you.
fig/http-message-util              1.1.5   Utility classes and constants for use with PSR-7 (psr/http-message)
firebase/php-jwt                   v5.4.0  A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.
google/auth                        v1.18.0 Google Auth Library for PHP
google/cloud-core                  v1.43.0 Google Cloud PHP shared dependency, providing functionality useful to all components.
google/cloud-storage               v1.25.1 Cloud Storage Client for PHP
google/crc32                       v0.1.0  Various CRC32 implementations
graham-campbell/result-type        v1.0.2  An Implementation Of The Result Type
guzzlehttp/guzzle                  7.3.0   Guzzle is a PHP HTTP client library
guzzlehttp/promises                1.4.1   Guzzle promises library
guzzlehttp/psr7                    2.1.0   PSR-7 message implementation that also provides common utility methods
hamcrest/hamcrest-php              v2.0.1  This is the PHP port of Hamcrest Matchers
illuminate/auth                    v8.63.0 The Illuminate Auth package.
illuminate/broadcasting            v8.63.0 The Illuminate Broadcasting package.
illuminate/bus                     v8.63.0 The Illuminate Bus package.
illuminate/cache                   v8.62.0 The Illuminate Cache package.
illuminate/collections             v8.63.0 The Illuminate Collections package.
illuminate/config                  v8.63.0 The Illuminate Config package.
illuminate/console                 v8.63.0 The Illuminate Console package.
illuminate/container               v8.63.0 The Illuminate Container package.
illuminate/contracts               v8.63.0 The Illuminate Contracts package.
illuminate/database                v8.63.0 The Illuminate Database package.
illuminate/encryption              v8.63.0 The Illuminate Encryption package.
illuminate/events                  v8.63.0 The Illuminate Events package.
illuminate/filesystem              v8.63.0 The Illuminate Filesystem package.
illuminate/hashing                 v8.63.0 The Illuminate Hashing package.
illuminate/http                    v8.63.0 The Illuminate Http package.
illuminate/log                     v8.63.0 The Illuminate Log package.
illuminate/macroable               v8.62.0 The Illuminate Macroable package.
illuminate/pagination              v8.63.0 The Illuminate Pagination package.
illuminate/pipeline                v8.63.0 The Illuminate Pipeline package.
illuminate/queue                   v8.63.0 The Illuminate Queue package.
illuminate/session                 v8.63.0 The Illuminate Session package.
illuminate/support                 v8.63.0 The Illuminate Support package.
illuminate/testing                 v8.63.0 The Illuminate Testing package.
illuminate/translation             v8.63.0 The Illuminate Translation package.
illuminate/validation              v8.63.0 The Illuminate Validation package.
illuminate/view                    v8.63.0 The Illuminate View package.
kreait/clock                       1.1.0   A PHP 7.0 compatible clock abstraction
kreait/firebase-php                5.24.0  Firebase Admin SDK
kreait/firebase-tokens             1.16.1  A library to work with Firebase tokens
kreait/laravel-firebase            3.1.0   A Laravel package for the Firebase PHP Admin SDK
laravel/lumen-framework            v8.2.7  The Laravel Lumen Framework.
laravel/serializable-closure       v1.0.2  Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.
laravel/tinker                     v2.6.2  Powerful REPL for the Laravel framework.
lcobucci/clock                     2.0.0   Yet another clock abstraction
lcobucci/jwt                       4.0.4   A simple library to work with JSON Web Token and JSON Web Signature
mailjet/mailjet-apiv3-php          v1.5.5  PHP wrapper for the Mailjet API
mockery/mockery                    1.4.4   Mockery is a simple yet flexible PHP mock object framework
monolog/monolog                    2.3.5   Sends your logs to files, sockets, inboxes, databases and various web services
mtdowling/jmespath.php             2.6.1   Declaratively specify how to extract elements from a JSON document
myclabs/deep-copy                  1.10.2  Create deep copies (clones) of your objects
nesbot/carbon                      2.53.1  An API extension for DateTime that supports 281 different languages.
nikic/fast-route                   v1.3.0  Fast request router for PHP
nikic/php-parser                   v4.13.0 A PHP parser written in PHP
opis/closure                       3.6.2   A library that can be used to serialize closures (anonymous functions) and arbitrary objects.
phar-io/manifest                   2.0.3   Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    3.1.0   Library for handling version information and constraints
phenx/php-font-lib                 0.5.2   A library to read, parse, export and make subsets of different types of font files.
phenx/php-svg-lib                  0.3.4   A library to read, parse and export to PDF SVG files.
phpdocumentor/reflection-common    2.2.0   Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock  5.2.2   With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver        1.5.1   A PSR-5 based resolver of Class names, Types and Structural Element Names
phpoption/phpoption                1.8.0   Option Type for PHP
phpspec/prophecy                   1.14.0  Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          9.2.7   Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          3.0.5   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                3.1.1   Invoke callables with a timeout
phpunit/php-text-template          2.0.4   Simple template engine.
phpunit/php-timer                  5.0.3   Utility class for timing
phpunit/phpunit                    9.5.10  The PHP Unit Testing framework.
psr/cache                          1.0.1   Common interface for caching libraries
psr/container                      1.1.1   Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher               1.0.0   Standard interfaces for event handling.
psr/http-client                    1.0.1   Common interface for HTTP clients
psr/http-factory                   1.0.1   Common interfaces for PSR-7 HTTP message factories
psr/http-message                   1.0.1   Common interface for HTTP messages
psr/log                            1.1.4   Common interface for logging libraries
psr/simple-cache                   1.0.1   Common interfaces for simple caching
psy/psysh                          v0.10.9 An interactive shell for modern PHP.
ralouphie/getallheaders            3.0.3   A polyfill for getallheaders.
ramsey/collection                  1.2.1   A PHP library for representing and manipulating collections.
ramsey/uuid                        4.2.3   A PHP library for generating and working with universally unique identifiers (UUIDs).
riverline/multipart-parser         2.0.8   One class library to parse multipart content with encoding and charset support.
rize/uri-template                  0.3.3   PHP URI Template (RFC 6570) supports both expansion & extraction
sabberworm/php-css-parser          8.3.1   Parser for CSS Files written in PHP
sebastian/cli-parser               1.0.1   Library for parsing CLI options
sebastian/code-unit                1.0.8   Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup 2.0.3   Looks up which function or method a line of code belongs to
sebastian/comparator               4.0.6   Provides the functionality to compare PHP values for equality
sebastian/complexity               2.0.2   Library for calculating the complexity of PHP code units
sebastian/diff                     4.0.4   Diff implementation
sebastian/environment              5.1.3   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 4.0.3   Provides the functionality to export PHP variables for visualization
sebastian/global-state             5.0.3   Snapshotting of global state
sebastian/lines-of-code            1.0.3   Library for counting the lines of code in PHP source code
sebastian/object-enumerator        4.0.4   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector         2.0.4   Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        4.0.4   Provides functionality to recursively process PHP variables
sebastian/resource-operations      3.0.3   Provides a list of PHP built-in functions that operate on resources
sebastian/type                     2.3.4   Collection of value objects that represent the types of the PHP type system
sebastian/version                  3.0.2   Library that helps with managing the version number of Git-hosted PHP projects
symfony/console                    v5.3.7  Eases the creation of beautiful and testable command line interfaces
symfony/deprecation-contracts      v2.4.0  A generic function and convention to trigger deprecation notices
symfony/error-handler              v5.3.7  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           v5.3.7  Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts v2.4.0  Generic abstractions related to dispatching event
symfony/finder                     v5.3.7  Finds files and directories via an intuitive fluent interface
symfony/http-client-contracts      v2.4.0  Generic abstractions related to HTTP clients
symfony/http-foundation            v5.3.7  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                v5.3.9  Provides a structured process for converting a Request into a Response
symfony/mime                       v5.3.8  Allows manipulating MIME messages
symfony/polyfill-ctype             v1.23.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme     v1.23.1 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn          v1.23.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.23.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.23.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72             v1.23.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.23.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80             v1.23.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81             v1.23.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/process                    v5.3.7  Executes commands in sub-processes
symfony/service-contracts          v2.4.0  Generic abstractions related to writing services
symfony/string                     v5.3.7  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                v5.3.9  Provides tools to internationalize your application
symfony/translation-contracts      v2.4.0  Generic abstractions related to translation
symfony/var-dumper                 v5.3.8  Provides mechanisms for walking through any arbitrary PHP variable
theseer/tokenizer                  1.2.1   A small library for converting tokenized PHP source code into XML and potentially other formats
vlucas/phpdotenv                   v5.3.1  Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
voku/portable-ascii                1.5.6   Portable ASCII library - performance optimized (ascii) string functions for php.
webmozart/assert                   1.10.0  Assertions to validate method input/output with nice error messages.

PHP version and extensions

composer-plugin-api    2.0.0    The Composer Plugin API
composer-runtime-api   2.0.0    The Composer Runtime API
ext-bcmath             7.4.2    The bcmath PHP extension
ext-calendar           7.4.2    The calendar PHP extension
ext-ctype              7.4.2    The ctype PHP extension
ext-curl               7.4.2    The curl PHP extension
ext-date               7.4.2    The date PHP extension
ext-dom                20031129 The dom PHP extension
ext-fileinfo           7.4.2    The fileinfo PHP extension
ext-filter             7.4.2    The filter PHP extension
ext-ftp                7.4.2    The ftp PHP extension
ext-gd                 7.4.2    The gd PHP extension
ext-hash               7.4.2    The hash PHP extension
ext-iconv              7.4.2    The iconv PHP extension
ext-imap               7.4.2    The imap PHP extension
ext-intl               7.4.2    The intl PHP extension
ext-json               7.4.2    The json PHP extension
ext-libxml             7.4.2    The libxml PHP extension
ext-mailparse          3.1.0    The mailparse PHP extension
ext-mbstring           7.4.2    The mbstring PHP extension
ext-mysqli             7.4.2    The mysqli PHP extension
ext-mysqlnd            0        The mysqlnd PHP extension (actual version: mysqlnd 7.4.2)
ext-openssl            7.4.2    The openssl PHP extension
ext-pcre               7.4.2    The pcre PHP extension
ext-pdo                7.4.2    The PDO PHP extension
ext-phar               7.4.2    The Phar PHP extension
ext-readline           7.4.2    The readline PHP extension
ext-reflection         7.4.2    The Reflection PHP extension
ext-session            7.4.2    The session PHP extension
ext-simplexml          7.4.2    The SimpleXML PHP extension
ext-sockets            7.4.2    The sockets PHP extension
ext-spl                7.4.2    The SPL PHP extension
ext-tokenizer          7.4.2    The tokenizer PHP extension
ext-xdebug             2.9.6    The xdebug PHP extension
ext-xml                7.4.2    The xml PHP extension
ext-xmlreader          7.4.2    The xmlreader PHP extension
ext-xmlwriter          7.4.2    The xmlwriter PHP extension
ext-zip                1.15.5   The zip PHP extension
ext-zlib               7.4.2    The zlib PHP extension
lib-curl               7.67.0   The curl library
lib-curl-libssh2       1.8.2    curl libssh2 version
lib-curl-openssl       1.1.1.4  curl OpenSSL version (1.1.1.4)
lib-curl-zlib          1.2.11   curl zlib version
lib-date-timelib       2018.03  date timelib version
lib-date-zoneinfo      2019.3   zoneinfo ("Olson") database for date
lib-fileinfo-libmagic  537      fileinfo libmagic version
lib-gd                 2.0.35   The gd library
lib-gd-freetype        2.9.1    freetype version for gd
lib-gd-libjpeg         9.0      libjpeg version for gd
lib-gd-libpng          1.6.34   libpng version for gd
lib-gd-libxpm          3.5.12   libxpm version for gd
lib-iconv              1.16     The iconv library
lib-icu                65.1     The ICU unicode and globalization support library
lib-icu-cldr           36       ICU CLDR project version
lib-icu-unicode        12.1.0   ICU unicode version
lib-icu-zoneinfo       2019.3   zoneinfo ("Olson") database for icu
lib-libxml             2.9.10   libxml library version
lib-mbstring-libmbfl   1.3.2    mbstring libmbfl version
lib-mbstring-oniguruma 6.9.4    mbstring oniguruma version
lib-openssl            1.1.1.4  OpenSSL 1.1.1d  10 Sep 2019
lib-pcre               10.33    The pcre library
lib-pcre-unicode       11.0.0   PCRE Unicode version support
lib-zlib               1.2.11   The zlib library
php                    7.4.2    The PHP interpreter
php-64bit              7.4.2    The PHP interpreter, 64bit
php-ipv6               7.4.2    The PHP interpreter, with IPv6 support

On which operating system(s) does the issue occur?

  • Linux
  • MacOS
  • Windows

Steps to reproduce the issue.

$timeOffset = $database->getReference(".info/serverTimeOffset")->getValue();

Error message/Stack trace

In Database.php line 43:

The child key ".info" contains one of the following invalid characters: ".$#[]"

In Validator.php line 66:

The child key ".info" contains one of the following invalid characters: ".$#[]"

Additional information

No response

@jeromegamez
Copy link
Member

When I remove the . char from the validator in https://github.com/kreait/firebase-php/blob/5.x/src/Firebase/Database/Reference/Validator.php#L14 and try to call this reference, the Firebase REST API returns the error Invalid path: Invalid token in path, and I also can't save a value in the RTDB in the Firebase Console on a path that contains a dot.

If this is supposed to work, can you please show me some official documentation or a place where this works in one of the official Admin SDKs?

@rvalitov
Copy link
Author

Thank you for a prompt reply. I found information about the serverTimeOffset here https://firebase.google.com/docs/database/web/offline-capabilities#server-timestamps
I didn't find any specific mentions about this parameter in Admin SDK, perhaps I didn't search good. I expect that Admin SDK allows to work with all the functionality described in Realtime database manual, therefore I expect that serverTimeOffset should also be supported. At least I didn't find any notice that serverTimeOffset is not available.

@rvalitov
Copy link
Author

Dot is really a special reserved character, that can only be used in special reserved path references like .info. This path is read only and is handled by Firebase, not available for save.

@jeromegamez
Copy link
Member

This is a feature available in the Firebase Client SDK, not the Admin SDK, and honestly… I don't know how they do it 😅. It's definitely not a real database reference or the Firebase REST API doesn't allow access to it.

However, I will consider this a feature request. In the meantime, you can simulate the same behavior with something like the following:

$offsetRef = $db->getReference('serverTimeOffset')->set(\Kreait\Firebase\Database::SERVER_TIMESTAMP);
$offsetValue = (int) $offsetRef->getValue();

$here = new DateTimeImmutable();
$there = DateTime::createFromFormat('U.v', number_format($offsetValue/1000, 3, '.', ''));

$offset = $there->getTimestamp() - $here->getTimestamp();

@github-actions
Copy link
Contributor

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale. Please make sure to update to the latest version and check if that solves the issue. Let me know if that works for you by leaving a 👍. Because this issue is marked as stale, it will be closed and locked in 7 days if no further activity occurs. Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants