This application demonstrates how to report errors on App Engine Standard for PHP 7.2. It also demonstrates how different PHP error types are handled.
To set up error reporting in your App Engine PHP 7.2 application, simply follow these two steps:
- Install the Google Cloud Error Reporting client library
composer require google/cloud-error-reporting
- Create a
php.inifile in the root of your project and setauto_prepend_fileto the following:; in php.ini auto_prepend_file=/srv/vendor/google/cloud-error-reporting/src/prepend.php
The prepend.php file will be executed prior to each request, which
registers the client library's error handler.
If you cannot modify your php.ini, the prepend.php file can be manually
included to register the error handler:
# This works for files in the root of your project. Adjust __DIR__ accordingly.
require_once __DIR__ . '/vendor/google/cloud-error-reporting/src/prepend.php';- Install
composer - Install dependencies by running:
composer install
- Install the Google Cloud SDK.
Deploy the samples by doing the following:
gcloud config set project YOUR_PROJECT_ID
gcloud app deploy
gcloud app browse
The last command will open https://{YOUR_PROJECT_ID}.appspot.com/
in your browser. Browse to / to see a list of examples to execute.
Uncomment the require_once statement at the top of index.php,
or add the auto_prepend_file above to your local php.ini.
Now run the sample locally using PHP's build-in web server:
# export environemnt variables locally which are set by App Engine when deployed
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT_ID
export GAE_SERVICE=local
export GAE_VERSION=testing
# Run PHP's built-in web server
php -S localhost:8000
Browse to localhost:8000 to see a list of examples to execute.
