Protobuf implementations

There are two implementations that are available for PHP:

  1. C: Uses the Protobuf PHP extension which gives better performance.
  2. PHP: Uses the google/protobuf PHP package which is easier to implement.

We recommend using the C implementation when possible, but PHP may be needed in some cases (such as when limited by security or technical constraints).

The PHP implementation is automatically installed like any other googleapis/gax-php dependencies in Composer, but it is used at runtime only if the C implementation is not installed and configured.

C implementation

To install and configure the Protobuf PHP extension:

  1. Run sudo pecl install protobuf from the command line.
  2. Add an line to the php.ini file.

PHP implementation

Make sure the C implementation is disabled and all the dependencies of the googleapis/gax-php library are installed:

  1. Comment out any line in php.ini.
  2. Run composer install from the directory that contains the composer.json file of the project being worked on. The composer.json should specify google-ads-php or any project that requires it as a dependence.

Determine which implementation is being used

Run php -i | grep protobuf:

  • If not empty, you're using the C implementation.
  • Otherwise, you're not using the C implementation and the Google Ads API PHP library will rely on the PHP implementation (if installed correctly using Composer).