Page Summary
-
Two PHP implementations for Protobuf are available: C (better performance, requires extension) and PHP (easier implementation, uses a package).
-
The C implementation is recommended when possible, but the PHP implementation can be used when necessary.
-
The PHP implementation is used automatically if the C implementation is not installed and configured.
-
Instructions are provided for installing and configuring both the C and PHP implementations.
-
A command is available to determine which Protobuf implementation is currently in use.
There are two Protobuf implementations available for PHP:
- C: Uses the Protobuf PHP C extension, which provides significantly better runtime performance.
- PHP: Uses the
google/protobufPHP package, which requires no additional system extensions.
Use the C implementation when possible, though the pure PHP implementation can be used when security or environment constraints prevent installing C extensions.
The PHP implementation is automatically installed as a dependency of
googleapis/gax-php in Composer, and is used at runtime only if
the C implementation is not installed and enabled.
C implementation
To install and configure the Protobuf PHP C extension:
Install the extension using PECL:
sudo pecl install protobufEnable the extension in your active
php.inifile (for both CLI and web server environments such as PHP-FPM or Apache; runphp --inito locate the CLI configuration file):extension=protobuf.so
PHP implementation
To use the pure PHP implementation, ensure that the C implementation is disabled
and all dependencies of googleapis/gax-php are installed:
- Comment out or remove any
extension=protobuf.so(orextension=php_protobuf.dll) line in yourphp.inifiles. Run
composer installfrom the directory that contains thecomposer.jsonfile of your project. Thecomposer.jsonfile should specifygoogleads/google-ads-phpas a dependency.
Determine which implementation is being used
Run the following command in your terminal to check whether the C extension is enabled in your PHP CLI environment:
php -i | grep protobuf
- If the output is not empty (for example,
protobuf support => enabled), you are using the C implementation. - Otherwise, you are not using the C implementation, and the Google Ads API PHP library automatically falls back to the pure PHP implementation installed by Composer.