There are two Protobuf implementations available for PHP:

1. **C** : Uses the [Protobuf PHP C extension](https://pecl.php.net/package/protobuf), which provides significantly better runtime performance.
2. **PHP** : Uses the [`google/protobuf` PHP package](https://packagist.org/packages/google/protobuf), 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`](https://github.com/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:

1. Install the extension using PECL:

       sudo pecl install protobuf

2. Enable the extension in your active `php.ini` file (for both CLI and web
   server environments such as PHP-FPM or Apache; run `php --ini` to locate the
   CLI configuration file):

       extension=protobuf.so

   > [!NOTE]
   > **Note:** On Windows, add `extension=php_protobuf.dll` to `php.ini` instead.

## PHP implementation

To use the pure PHP implementation, ensure that the C implementation is disabled
and all dependencies of [`googleapis/gax-php`](https://github.com/googleapis/gax-php) are installed:

1. Comment out or remove any `extension=protobuf.so` (or `extension=php_protobuf.dll`) line in your `php.ini` files.
2. Run `composer install` from the directory that contains the `composer.json`
   file of your project. The `composer.json` file should specify
   `googleads/google-ads-php` as a dependency.

   > [!IMPORTANT]
   > **Key Point:** Typically, the Protobuf version that this PHP library relies on is transitively specified in the [`composer.json` file of
   > `google/gax`](https://github.com/googleapis/gax-php/blob/master/composer.json). For performance or compatibility reasons, a minimum Protobuf version may also be specified directly in the PHP client library's [`composer.json`](https://github.com/googleads/google-ads-php/blob/HEAD/composer.json).

## 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.