Skip to content


Subversion checkout URL

You can clone with
Download ZIP
PHP APM (Alternative PHP Monitor)
C Other
branch: master
Failed to load latest commit information.
.travis.scripts Added: Support for Travis CI
tests Fixed: parse error test failing on PHP 5.4
.gitignore Changed: ignore .lo files
.travis.yml Changed: travis email notification
AUTHORS Added: authors file
CONTRIBUTORS Fixed: possible segfault with PHP 5.5
LICENSE license change to PHP licence
NEWS Changed: releasing 2.0.5 Merge pull request #23 from johnkeates/master
apm.c Fixed: missing apm.statsd_exception_mode and apm.socket_exception_mode
apm.ini Fixed: missing apm.statsd_exception_mode and apm.socket_exception_mode
backtrace.c Changed: optimized stacktrace by prefering smart_str_appendl over sma…
backtrace.h Changed: Copyright year update
config.m4 Allow to define sqlite3 default DB path at build time
config.w32 Fixed: sqlite3.h file not found in Windows build
driver_mysql.c Changed: apm_driver_##name##_insert_request removed, can be static
driver_mysql.h Fixed: #13 ZTS build is broken (take 2)
driver_socket.c Changed: using PHP ext conventions (C comments only)
driver_socket.h Fixed: #13 ZTS build is broken (take 2)
driver_sqlite3.c Changed: respecting PHP CS
driver_sqlite3.h Fixed: #13 ZTS build is broken (take 2)
driver_statsd.c Changed: removed unnecessary includes
driver_statsd.h Fixed: #13 ZTS build is broken (take 2)
package.xml Changed: releasing 2.0.5
php_apm.h Changed: releasing 2.0.5

APM (Alternative PHP Monitor)

Build Status

APM (Alternative PHP Monitor) is a monitoring extension enabling native Application Performance Management (APM) for PHP. It doesn't require any modification to your application's code and let's you collect performance metrics as well as catching issues that may arise.


From PECL:

  1. $ sudo pecl install apm

From source:

  1. $ git clone
  2. $ cd php-apm
  3. $ phpize
  4. Configure the extension, by default, sqlite3, MariaDB/MySQL, StatsD and Socket support are enabled:

    $ ./configure [--with-sqlite3[=DIR]] [--with-mysql[=DIR]] [--enable-statsd] [--enable-socket] [--with-debugfile[=FILE]]

    To disable the support of a --with-* switch, use: --without-*, example: $ ./configure --without-sqlite3 To disable the support of a --enable-* switch, use: --disable-*, example: $ ./configure --disable-socket

  5. Compile it:

    $ make [-j]

    Tip: use -j to activate parallel compilation.

  6. Install it:

    $ sudo make install



  1. Activate the extension in the php configuration by adding:

    Note: APM depends on JSON, so the extension must be loaded after JSON!

MariaDB/MySQL driver

The MariaDB/MySQL driver lets you store errors and stats in a local, remote or shared database.

  1. Create a user/database for storing APM events.
  2. Set the following settings in the php configuration:

    ; Error reporting level specific to the MariaDB/MySQL driver, same level as for PHP's *error_reporting*

SQLite driver

The SQLite driver lets you store errors and stats in a local SQLite database.

Note that if performance matters, you should better use the MariaDB/MySQL driver.

  1. Create the directory for the SQLite database as it will be referenced in the setting: apm.sqlite_db_path (see next step):

    $ mkdir -p /var/php/apm/db/
    $ chmod a+rwx /var/php/apm/db/
  2. Set the following settings in the php configuration:

    ; The directory containing the "events" file
    ; Error reporting level specific to the SQLite3 driver, same level as for PHP's *error_reporting*

StatsD driver

The StatsD driver is handy to send performance metrics of your web sites/applications directly to StatsD, without interfering with your code. The most common backend for StatsD is Graphite, see [Etsy's blog post on StatsD/Graphite], but other backends exist as well.

  1. Install StatsD.
  2. Configure it in the php configuration:

    ; Whether to enable the statsd driver
    ; Host of the statsd server
    ; Port of the statsd server

Socket driver

The socket driver lets you send errors and stats directly by Unix and/or TCP sockets. This is handy if you want to write you own piece of code to handle those.

  1. Configure it in the php configuration:

    ; Whether to enable the socket driver
    ; Socket path (accept multiple entries, separated by "|", prefixed with "file:" or "tcp:")
    ; Example: apm.socket_path=file:/var/tmp/apm.sock|tcp:localhost:1234

Web frontend

The web frontend to visualize the data is now available at:

Advanced configuration

; Application identifier, helps identifying which application is being monitored
apm.application_id="My application"
; Enable the capture of events such as errors, notices, warnings,...
; Maximum duration in ms a request can take before it gets recorded
; Maximum User CPU time in ms a request can take before it gets recorded
; Maximum System CPU time in ms a request can take before it gets recorded
; Boolean controlling whether the stacktrace should be stored or not
; Boolean controlling whether the ip should be stored or not
; Boolean controlling whether the cookies should be stored or not
; Boolean controlling whether the POST variables should be stored or not
; Maximum recursion depth used when dumping a variable
; NOTE: With today's application complexity, the amount of data collected in stacktraces
; including arguments can lead to several thousands of MiB of memory consumed.
; We recommend increasing this value with care.

; For the configuration below, <driver_name> can be any of: sqlite, mysql, statsd or socket

; Activate or deactivate a specific driver (note also that it must be compiled in to be activated).
; Whether to collect stats for this driver (ATTENTION: Has a small performance overhead when used with a DB drivers!)
; Error reporting level specific to this driver
; Control which exceptions to collect (0: none exceptions collected, 1: collect uncaught exceptions (default), 2: collect ALL exceptions)
; Stores silenced events (Errors, warnings, notices,... that are muted with the PHP '@' operator)

For a list of all PHP ini directives, take a look at the apm.ini file.

Common issues

  • SQLite database isn't created: this usually happens when your webserver or PHP process (fcgi, fpm) has no filesystem access:

    • Check your configuration: maybe SQLite isn't configured properly for APM
    • Check permissions on the directory and events file for the user that PHP runs as (sometimes it's your webserver user)
    • Check open_basedir restrictions
  • Not all data on the specific PHP scripts in which errors occur is collected:

    • Usually an access issue, check permissions
    • Sometimes this is due to open_basedir restrictions
  • APM is configured correctly, but nothing shows up, and phpinfo() doesn't show anyting related to APM:

    • APM wasn't actually loaded, check if the ini file you configured is actually used by PHP
    • the APM module was tried, but fatal errors prevented it from loading; check the PHP error log, usually a dependency like JSON wasn't loaded yet
Something went wrong with that request. Please try again.