Jump to Content
Google Cloud

PHP 7.1 for Google App Engine is generally available

September 29, 2017
Brent Shaffer

Google Cloud Platform

Earlier this year, we announced PHP 7.1 Google App Engine in beta. We PHP lovers at Google are proud to announce that PHP 7.1 is now generally available on Google App Engine, our easy-to-use platform for building, deploying, managing and automatically scaling services on Google’s infrastructure. The PHP 7.1 runtime is available for App Engine flexible environment.

Video Thumbnail

Along with achieving general availability for PHP 7.1, the new PHP runtime includes a few exciting new features.

Extension enabler


The list of PHP extensions you can use with the App Engine runtime now includes any PHP extension that is stable (1.0 and above) and does not require a EULA. You can find a complete list on the PHP runtime page.

This is great news, but to make it even better you can now quickly and easily activate any of these extensions in your deployment by requiring them with Composer.

Loading...

This is equivalent to adding the name of the extension, prefixed with “ext-”, to your application’s composer.json:

Loading...

You can still install a custom extension or a specific version of a supported extension, but this will require extending the PHP runtime.

Stackdriver Logging and Error Reporting support

https://storage.googleapis.com/gweb-cloudblog-publish/images/image1kg3o.max-700x700.PNG

Logging to Stackdriver from your PHP application is very simple. The first requirement is to install the Composer package google/cloud version 0.33 or higher.

Loading...

Now set enable_stackdriver_integration to true

in the runtime_config section of app.yaml:

Loading...

This configuration tells the PHP runtime to dispatch the batch-processing daemon to handle your logs behind the scenes. This ensures that when your application writes a log, calls to the Stackdriver API happen in another process so as not to add latency to your application.
Now you can create a PsrBatchLogger instance in your code and log to Stackdriver:

Loading...

Additionally, the enable_stackdriver_integration flag sets up an auto-prepend file for error reporting. This means uncaught exceptions and fatal errors are formatted and visible in Cloud Console Error Reporting!

Loading...

Loading...

If you’d rather use individual Google Cloud packages, ensure you have both google/cloud-logging and google/cloud-error-reporting installed. When installing locally, use --ignore-platform-reqs or install gRPC according to the installation instructions.

Loading...

Stackdriver Logging for Laravel

After you’ve configured the enable_stackdriver_integration, you can enable Stackdriver integration in an app based on the Laravel PHP framework by modifying bootstrap/app.php:
Loading...

For Error Reporting, add an import and call our `exceptionHandler` in the `report` function in `app/Exceptions/Handler.php`:

Loading...

That's it! The logs are sent to Stackdriver Logging with the logName 'app'. Unhandled exceptions are sent to the logName 'app-error', and will show up in Stackdriver Error Reporting.

gRPC Support

Google’s highly performant RPC protocol gRPC is built right into the PHP runtime. This allows you to quickly get started making calls to Cloud Spanner and other gRPC-specific APIs. You can enable the extension in composer.json and download the client library:
Loading...

Now you can make calls to Spanner in your application:

Loading...

By replacing YOUR_INSTANCE_ID and YOUR_DATABASE_ID with the proper values, your application now displays the text “Hello Spanner”!

Our commitment to PHP and open source

At Google, we’re committed to open source -- and that goes for the new core PHP Docker runtime, google-cloud composer package and Google API client:

We’re thrilled to welcome PHP developers to Google Cloud Platform, and we’re invested in making you as productive as possible. This is just the start -- stay tuned to the blog and our GitHub repositories to catch the next wave of PHP support on GCP.

We can’t wait to hear from you. Feel free to reach out to us on Twitter, or request an invite to the Google Cloud Slack community and join the #PHP channel.

Posted in