Google Ads API is returning to beta status. Please read our blog post for more details.

Performance

The PHP client library eases interactions with the Google Ads API, with minimal configuration on your part. However, performance highly depends on how the library is used and integrated.

Most of these best practices are applicable to all languages. This guide goes through the ones that are specific to PHP.

Protobuf implementation

Protobuf is used by gRPC and the Google Ads API for request and response messages. Two implementations are available, though the one written in C has the better performance.

See the Protobuf guide for more information.

Operation mode of PHP interpreter

PHP is a versatile scripting language and has many operation modes differing based on the usage. PHP CGI (Common Gateway Interface) has a notable advantage because it can share resources between executions.

PHP version

It is a good practice to regularly upgrade to a newer PHP version as it usually comes with better overall performance. List of supported PHP versions.

Development vs production

PHP is an interpreted language in that it first compiles instructions before executing them. This is usually advantageous since during development time, sources often change while execution time is not that crucial. However, the opposite is true at production time as stability and performance become the main concerns.

Cache

Caching is common and highly recommended because it both improves performance and increases stability by storing precompiled script instructions.

OPcache is the most commonly used solution and it is available by default.

Autoload

Autoload is common because it both improves performance and increases stability by loading precompiled information about classes.

The PHP client library conforms to PSR-4 for autoloading and provides the definition as part of the composer.json file. Dedicated options of Composer such as --optimize-autoloader or --classmap-authoritative for example can then be used out of the box.

Logging

Setting loggers to a high level like ERROR can help reduce execution time overhead and memory consumption.

See the Logging guide for more information.

Debugging & profiling

We recommend disabling debugger and profiler tools as they usually come with some execution time overhead.

Preload

Since PHP 7.4, OPcache preloading can be used to preload scripts in memory, going one step further compared to regular caching.

A script has to be designed to take advantage of this feature, but the PHP client library doesn't since there is no generic way of implementing OPcache preloading and the trade-off between memory usage and performance gain is highly specific to a given project and execution.