for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Bavix\XHProf\Services;
use Bavix\XHProf\Providers\ProviderInterface;
use Bavix\XHProf\Providers\TidewaysProvider;
use Bavix\XHProf\Providers\XHProfProvider;
use function extension_loaded;
use function mt_getrandmax;
use function mt_rand;
class XHProfService
{
/**
* @var ProviderInterface
*/
protected $provider;
* XHProfService constructor.
public function __construct()
if (!extension_loaded(config('xhprof.extension_name', 'xhprof'))) {
return;
}
if (!config('xhprof.enabled', false)) {
$freq = config('xhprof.freq', 0.01);
if ($freq >= (mt_rand() / mt_getrandmax())) {
switch (config('xhprof.provider', XHProfProvider::class)) {
case TidewaysProvider::class:
$this->provider = new TidewaysProvider();
break;
default:
case XHProfProvider::class:
$this->provider = new XHProfProvider();
* @return void
public function enable(): void
if ($this->provider) {
$this->provider->enable();
public function disable(): void
$this->provider->disable();