diff --git a/Civi/API/Subscriber/DebugSubscriber.php b/Civi/API/Subscriber/DebugSubscriber.php index ac1abad89494..0e6be75478e7 100644 --- a/Civi/API/Subscriber/DebugSubscriber.php +++ b/Civi/API/Subscriber/DebugSubscriber.php @@ -24,6 +24,29 @@ class DebugSubscriber implements EventSubscriberInterface { */ private $debugLog; + /** + * @var bool + */ + private $enableStats; + + public function __construct() { + $version = phpversion('xdebug'); + switch ($version ? substr($version, 0, 2) : NULL) { + case '2.': + $this->enableStats = function_exists('xdebug_time_index'); + break; + + case '3.': + $xdebugMode = explode(',', ini_get('xdebug.mode')); + $this->enableStats = in_array('develop', $xdebugMode); + break; + + default: + $this->enableStats = FALSE; + break; + } + } + /** * @return array */ @@ -70,7 +93,7 @@ public function onApiRespond(\Civi\API\Event\RespondEvent $event) { if (isset($this->debugLog) && $this->debugLog->getMessages()) { $debug['log'] = $this->debugLog->getMessages(); } - if (function_exists('xdebug_time_index')) { + if ($this->enableStats) { $debug['peakMemory'] = xdebug_peak_memory_usage(); $debug['memory'] = xdebug_memory_usage(); $debug['timeIndex'] = xdebug_time_index();