Skip to content

Instantly share code, notes, and snippets.

@rande
Created September 3, 2012 23:30
Show Gist options
  • Save rande/3614808 to your computer and use it in GitHub Desktop.
Save rande/3614808 to your computer and use it in GitHub Desktop.
<?php
// this check prevents access to debug front controllers that are deployed by accident to production servers.
// feel free to remove this, extend it, or make something more sophisticated.
if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
'84.14.82.2',
'88.175.92.100',
))) {
header('HTTP/1.0 403 Forbidden');
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
//require_once __DIR__.'/../app/autoload.php';
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
use Symfony\Component\HttpFoundation\Request;
use Ekino\Metric\Reporter\Xhprof\XhprofSample;
/**
* Initialize a Kernel
*/
$kernel = new AppKernel('dev', true);
//$kernel = new AppCache($kernel);
$kernel->loadClassCache();
/**
* Trace only 1/100 requests or if the xhprof parameter is defined into the query
* You can of course add you own logic : IP check, etc ...
*
* The xhprof overhead can be very important, so use it with care.
*/
if (rand(1, 100) == 50 || isset($_GET['_xhprof'])) {
// Very bad for production - use with care
// $flag = XhprofSample::FLAGS_MEMORY + XhprofSample::FLAGS_CPU;
// Almost good for production
$flag = XhprofSample::FLAGS_MEMORY;
$collector = new Ekino\Metric\Collector\XhprofCollector('php.', array('main' => 'main()'), $flag);
// If the die/exit method is called, the xhprof trace will be stored
register_shutdown_function(function() use ($collector, $kernel) {
$collector->stop();
$kernel->getContainer()->get('ekino.metric.manager')->addCollection($collector->get());
$kernel->getContainer()->get('ekino.metric.manager')->flush();
});
$collector->start();
}
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment