googleapis / google-cloud-php

Google Cloud Client Library for PHP
https://cloud.google.com/php/docs/reference
Apache License 2.0
1.09k stars 436 forks source link

Call to undefined function Ramsey\Uuid\Generator\random_bytes() #1289

Closed am-adnbp closed 6 years ago

am-adnbp commented 6 years ago

Trying to run the example code over Standard appengine:

    $bigQuery = new BigQueryClient([
        'projectId' => 'cloudframework-io'
    ]);
    $query = " SELECT
          CONCAT(
            'https://stackoverflow.com/questions/',
            CAST(id as STRING)) as url,
          view_count
        FROM `bigquery-public-data.stackoverflow.posts_questions`
        WHERE tags like '%google-bigquery%'
        ORDER BY view_count DESC
        LIMIT 10;";

        $queryJobConfig = $bigQuery->query($query);
        $queryResults = $bigQuery->runQuery($queryJobConfig);

The Google logs show the following error:

PHP Fatal error: Call to undefined function Ramsey\Uuid\Generator\random_bytes() in /base/data/home/apps/e~cloudframework-io/api:1.412536651015598677/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php on line 35


Following the error it seems that in RandomBytesGenerator.php uses the php command random_bytes() only available for PHP7 but Appengine Standard only allows to run php5.5

What can I do?

dwsupplee commented 6 years ago

@am-adnbp the UUID library we are using should be utilizing a fallback to a polyfill when not using PHP 7+.

Could you verify the polyfill library is installed, and if so which version, by running composer show please?

am-adnbp commented 6 years ago

guzzlehttp/guzzle dev-master c7faf23 Guzzle is a PHP HTTP client library guzzlehttp/promises dev-master 136531a Guzzle promises library guzzlehttp/psr7 dev-master 4b981cd PSR-7 message implementation that also provides common utility methods monolog/monolog 1.x-dev c465e11 Sends your logs to files, sockets, inboxes, databases and various web services paragonie/random_compat v9.99.99 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7 phpseclib/phpseclib 2.0.x-dev f381b1f PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc. psr/cache dev-master 78c5a01 Common interface for caching libraries psr/http-message dev-master f6561bf Common interface for HTTP messages psr/log dev-master 3490ba5 Common interface for logging libraries ralouphie/getallheaders 2.0.5 A polyfill for getallheaders. ramsey/uuid 3.x-dev 4c467ce Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID). rize/uri-template 0.3.2 PHP URI Template (RFC 6570) supports both expansion & extraction symfony/polyfill-ctype dev-master e3d8262 Symfony polyfill for ctype functions

dwsupplee commented 6 years ago

Thanks for the verification.

I tested out deploying the script you shared with the following debug information at the end:

echo 'Bytes: ' . random_bytes(5) . '<br/>';
echo 'PHP Version: ' . phpversion() . '<br/>';
echo 'Total queried rows: ' .  $queryResults->info()['totalRows'];

It appears the polyfill is working on my end when using app engine standard, as I received the following output:

screen shot 2018-09-13 at 10 35 40 am

My first thought is to try removing your vendor directory and composer.lock file if one exists and then re-install. If that doesn't do the trick, could you please share your composer.json, app.yaml, and php.ini?

am-adnbp commented 6 years ago

Receiving support from Google cases, they suggest to downgrade ramsey to 3.7.3, so I changed composer.json indicating to install "ramsey/uuid": "3.7.3"

And it worked!. :)

dwsupplee commented 6 years ago

That's great :)

After looking a bit more at the versions of the dependencies you have installed, it appears most of them are dev branches. Does your composer file have minimum-stability set to dev? I'd caution against this as there could be other gotchas/breaking changes in the dependencies we rely on. If you need to keep the stability at that level, I'd recommend setting the prefer-stable flag to true if possible.

https://getcomposer.org/doc/04-schema.md#minimum-stability

am-adnbp commented 6 years ago

Very useful, Thank you!!.