PHP 7.1 for Google App Engine is generally available
Brent Shaffer and Takashi Matsuo
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.
Along with achieving general availability for PHP 7.1, the new PHP runtime includes a few exciting new features.
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.
This is equivalent to adding the name of the extension, prefixed with “ext-”, to your application’s composer.json:
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
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.
enable_stackdriver_integration to true
runtime_config section of
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:
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!
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.
Stackdriver Logging for LaravelAfter you’ve configured the
enable_stackdriver_integration, you can enable Stackdriver integration in an app based on the Laravel PHP framework by modifying
For Error Reporting, add an import and call our `exceptionHandler` in the `report` function in `app/Exceptions/Handler.php`:
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 SupportGoogle’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:
Now you can make calls to Spanner in your application:
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 sourceAt 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.