I'm trying to implement Google's Text-To-Speech API on App Engine flex environment, but get this error:
"PHP message: PHP Fatal error: Uncaught Error: Call to undefined function Google\Protobuf\Internal\bccomp() in /app/web/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:941"
Once I solved the problem by requiring BCmath() in my composer.json
{
"require": {
"ext-bcmath": "*",
"google/cloud-text-to-speech": "^1.0",
"google/gax": "^1.3",
"grpc/grpc": "^1.4",
"google/auth": "^1.8",
"phpseclib/phpseclib": "^2.0",
"google/protobuf": "^3.11"
}
}
Then after reinstalling /vendor I can't get rid of the error message. I tried to install the BCmath extension by running
sudo apt install php7.2-bcmath
But it says that the extension is already installed. I run also this php -i | grep -i bcmath And get this message
/etc/php/7.2/cli/conf.d/20-bcmath.ini, bcmath BCMath support => enabled bcmath.scale => 0 => 0
The test for bccomp()
php -r "echo bccomp('1', '2');"
I get '-1' as supposed to be. It looks like the function works.
I even tried to enable the BCmath extention in php.ini
extension=bcmath.so
I placed the .ini file in the same directory as my /vendor and index.php. Still, after deployment the app by
gcloud app deploy
I still get the fatal error.
After 5days of breaking head, solution was found. It appears that BCMath is installed in PHP versions >= 7, but NOT enabled on Google App Engine. To enable it I did the following:
- I have created php.ini file and placed it in the same directory as app.yaml file, which might be different from the root directory of your app (index.php for example).
- In empty newly created php.ini have added one line:
extension=bcmath
Then require it in composer.json
{
"require": {
"ext-bcmath": "*"
}
}
Finally deploy the project
gcloud app deploy
And that's all!