Open main menu
MediaWiki extensions manual
OOjs UI icon advanced.svg
Release status: beta
License Apache License 2.0
Translate the Excimer extension if it is available at
Issues Open tasks ยท Report a bug

Excimer is a PHP 7.1+ extension that provides an interrupting timer and a sampling profiler.

Just enabling Tideways XHProf in PHP 7.2 causes a performance degradation of about 4%. We believe this is due to its installation of a zend_execute_ex hook, which intercepts all function calls. Even though this hook does nothing by default, just installing it causes PHP's VM to omit certain optimisations. The hook must be installed globally, it is not possible to enable it just for a particular request.

Excimer does not install a zend_execute_ex hook and thus cannot count function calls. It is thus suitable for production installation.


Excimer requires Linux.

Download the source code into an appropriate directory from git:

git clone

Or download a snapshot and unpack.


excimer here is the directory that excimer git repository was cloned to.

cd excimer
phpize && ./configure && make && sudo make install

Then add to the PHP configuration in an appropriate place. For example, in modern Debian-derived distributions you'd add a file to /etc/php/$version/mods-available (where $version is the version of PHP for which you compiled Excimer) and use the phpenmod command to enable it.

Reference documentationEdit

For now, please see the function stubs in the extension source.


Use a one-shot timer to limit the execution time of a functionEdit

$timer = new ExcimerTimer;
$timer->setInterval( 10 /* seconds */ );
$timer->setCallback( function () {
    throw new Exception( "The allowed time has been exceeded" );
} );

When the timer expires, Excimer sets a flag which is then checked by the PHP VM every time a function returns, and on every loop iteration. For CPU-intensive tasks, this is usually often enough. However, it will not interrupt long-running C functions such as MySQL connection attempts.

When the exception is thrown, the backtrace will show the callback being called from the interrupted code.

Note that the $timer variable must be kept alive, for example by keeping it in scope. If the timer object is destroyed, the timer will stop and the callback will not be called.

Use a periodic timer to gather time-series memory usage statisticsEdit

$timer = new ExcimerTimer;
$timer->setPeriod( 0.1 );
$startTime = microtime( true );
$timer->setCallback( function () use ( $startTime ) {
	$usage = sprintf( "%.2f", memory_get_usage() / 1048576 );
	$interval = microtime( true ) - $startTime;
	$date = sprintf( "%.2f", $interval );
} );

The process will be interrupted once every 100ms, and the current memory usage logged to a file.

Profile a process and produce a flame graphEdit

$profiler = new ExcimerProfiler;
$profiler->setPeriod( 0.01 );
$profiler->setEventType( EXCIMER_CPU );
register_shutdown_function( function () use ( $profiler ) {
	$pipe = popen( "/usr/local/bin/ > /tmp/profile.svg", "w" );
	fwrite( $pipe, $profiler->getLog()->formatCollapsed() );
} );

In this example, FlameGraph is presumed to be installed at /usr/local/bin/ An SVG file is written to /tmp/profile.svg. An example of the typical output can be seen at .

Profile a process and produce a function tableEdit

$profiler = new ExcimerProfiler;
$profiler->setPeriod( 0.01 );
$profiler->setEventType( EXCIMER_CPU );
register_shutdown_function( function () use ( $profiler ) {
	$report = sprintf( "%-79s %14s %14s\n", 'Function', 'Self', 'Inclusive' );
	foreach ( $profiler->getLog()->aggregateByFunction() as $id => $info ) {
		$report .= sprintf( "%-79s %14d %14d\n", $id, $info['self'], $info['inclusive'] );
	file_put_contents( '/tmp/aggregated.txt', $report );
} );

In this example, event counts are aggregated by function name, formatted in a fixed-width table, and written to a file. An example of typical output can be seen at .

External linksEdit