@ 2014-08-18T08:30:56Z <?php/* * This file is part of the SensioLabsProfiler SDK package. * * (c) SensioLabs <contact@sensiolabs.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */class SensioLabsProfilerProbe{ private static $fileFormat = __CLASS__; private static $profiler = false; private static $outputStream; private static $flags; private static $options; private static $defaultOptions = array( 'dump_extensions' => false, 'agent_timeout' => 0.25, 'server_keys' => array( 'HTTP_HOST', 'HTTP_USER_AGENT', 'HTTPS', 'REQUEST_METHOD', 'REQUEST_URI', 'SERVER_ADDR', 'SERVER_SOFTWARE', ), 'ignored_functions' => array( 'array_map', 'array_filter', 'array_reduce', 'array_walk', 'array_walk_recursive', 'call_user_func', 'call_user_func_array', 'call_user_method', 'call_user_method_array', 'forward_static_call', 'forward_static_call_array', 'iterator_apply', ), ); public static function enable($destination, $flags = null, array $options = array()) { if (isset(self::$outputStream)) { self::disable(); } isset($flags) or $flags = UPROFILER_FLAGS_MEMORY | UPROFILER_FLAGS_CPU; $requestTime = microtime(true); if (!$destination) { return false; } if (!empty($options['mock_profile_data']) && is_array($options['mock_profile_data'])) { self::$profiler = $options['mock_profile_data']; } elseif (function_exists('uprofiler_enable')) { self::$profiler = 'uprofiler'; } elseif (function_exists('xhprof_enable')) { self::$profiler = 'xhprof'; } else { $flags = 0; if (!isset(self::$outputStream)) { user_error('Neither uprofiler nor xhprof extension is enabled'); } } $options = array_merge_recursive(self::$defaultOptions, $options); self::$flags = $flags; self::$options = $options; self::profilerEnable(); if (!self::doEnable($destination, $requestTime, $response)) { self::profilerDisable(); if (null === $response) { $response = false; } } return null !== $response ? $response : true; } public static function disable() { if (self::$outputStream) { self::onEnd('', PHP_OUTPUT_HANDLER_END); self::$outputStream = false; return true; } } private static function doEnable($h, $requestTime, &$response) { $response = null; set_error_handler(function ($type, $message, $file, $line) { throw new ErrorException($message, 0, $type, $file, $line); }); try { if (!is_resource($h)) { if (($f = strpos($h, '://')) && in_array(substr($h, 0, $f), stream_get_transports(), true)) { if ($h = stream_socket_client($h, $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT)) { stream_set_timeout($h, 0, self::$options['agent_timeout']*1000000); $f = array(null, array($h), null); if (stream_select($f[0], $f[1], $f[2], 0, self::$options['agent_timeout']*1000000)) { self::fwrite($h, 'SensioLabsProfiler-Request: '.self::$options['agent_request']."\n"); $response = fgets($h, 4096); if (0 === strpos($response, 'SensioLabsProfiler-Response: ')) { self::$options['dump_extensions'] = "SensioLabsProfiler-Options: ext\n" === fgets($h, 4096); } else { fclose($h); $h = false; if (0 !== strpos($response, 'SensioLabsProfiler-Error: ')) { $response = "SensioLabsProfiler-Error: 102 Invalid agent response ($response)"; } } } else { fclose($h); $h = false; $response = "SensioLabsProfiler-Error: 101 agent connection timeout"; } $f = false; } else { $response = "SensioLabsProfiler-Error: 101 $errstr ($errno)"; } } else { $f = sprintf('%019.6F', $requestTime).'-'; $f .= substr(str_replace(array('+', '/'), array('', ''), base64_encode(md5(mt_rand(), true))), 0, 6); $h = fopen($h.'/'.$f.'.log', 'wb'); } if (!$h) { restore_error_handler(); return false; } } // This shared lock allows readers to wait for the end of the stream stream_is_local($h) and flock($h, LOCK_SH); stream_set_write_buffer($h, 0); // Loaded extensions list helps understanding runtime behavior $extensions = array(); if (self::$profiler && self::$options['dump_extensions']) { foreach (get_loaded_extensions() as $e) { $extensions[$e] = phpversion($e); } } // Keep only keys from $_COOKIE $data = array($_COOKIE, array()); array_walk_recursive($data, function (&$v) {$v = strlen($v);}); foreach (self::$options['server_keys'] as $e) { if (isset($_SERVER[$e])) { $data[1][$e] = $_SERVER[$e]; } } if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) { $e = $_SERVER['HTTP_X_ORIGINAL_URL']; } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) { $e = $_SERVER['HTTP_X_REWRITE_URL']; } elseif (!empty($_SERVER['IIS_WasUrlRewritten']) && !empty($_SERVER['UNENCODED_URL'])) { $e = $_SERVER['UNENCODED_URL']; } elseif (isset($_SERVER['REQUEST_URI'][0])) { $e = $_SERVER['REQUEST_URI']; if ('/' !== $e[0]) { $e = preg_replace('#^https?://[^/]+#', '', $e); } } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { $e = $_SERVER['ORIG_PATH_INFO']; if (!empty($_SERVER['QUERY_STRING'])) { $e .= '?'.$_SERVER['QUERY_STRING']; } } else { $e = ''; } if (!empty($e)) { $data[1]['REQUEST_URI'] = $e; } $data = 'file-format: '.self::$fileFormat."\n" .'request-mu: '.memory_get_usage(true)."\n" .'request-pmu: '.memory_get_peak_usage(true)."\n" .'request-start: '.$requestTime."\n" .'php-os: '.PHP_OS."\n" .'php-sapi: '.PHP_SAPI."\n" .'php-version: '.PHP_VERSION_ID."\n" // json_encode would loose non-UTF8 data .'php-extensions: '.base64_encode(serialize($extensions))."\n" .'_COOKIE: '.base64_encode(serialize($data[0]))."\n" .'_SERVER: '.base64_encode(serialize($data[1]))."\n"; $e = set_error_handler('var_dump'); restore_error_handler(); restore_error_handler(); $data .= self::getErrorHandler('error', array(__CLASS__, 'onError')) .self::getErrorHandler('exception', array(__CLASS__, 'onException')); set_error_handler($e); if (self::$profiler && function_exists('sys_getloadavg')) { $data .= 'sys-load-avg: '.implode(' ', sys_getloadavg())."\n"; } $data .= "\nmain()//1 0 0 0 0\n\n"; self::fwrite($h, $data); if (null === self::$outputStream) { register_shutdown_function(__CLASS__.'::onShutdown'); } self::$outputStream = $h; restore_error_handler(); return true; } catch (ErrorException $e) { $response = "SensioLabsProfiler-Error: 101 ".rawurlencode($e->getMessage()."\n\n".$e->getTraceAsString()); } restore_error_handler(); return self::$outputStream = false; } private static function getErrorHandler($type, $default = 'var_dump') { $s = "set_{$type}_handler"; if ($h = $s($default)) { $s = "restore_{$type}_handler"; $s(); } elseif ('var_dump' !== $default) { $h = $default; } $type .= '-handler: '; if ($h instanceof Closure) { $h = new ReflectionFunction($h); if (PHP_VERSION_ID >= 50400 && $s = $h->getClosureScopeClass()) { $h = $s->name.'::{closure}/'.$h->getStartLine().'-'.$h->getEndLine(); } else { $h = $h->name.'::'.implode('/', array_slice(explode('/', $h->getFileName()), -2)).'/'.$h->getStartLine().'-'.$h->getEndLine(); } } else { if (!is_array($h)) { if (is_object($h)) { $h = array($h, '__invoke'); } else { $h = explode('::', $h, 2); } } if (isset($h[1])) { $h = new ReflectionMethod($h[0], $h[1]); $h = $h->getDeclaringClass()->name.'::'.$h->name; } else { $h = $h[0]; } } $type .= "$h\n"; return $type; } private static function profilerEnable() { if (is_string(self::$profiler)) { $p = self::$profiler.'_enable'; return $p(self::$flags, self::$options); } } private static function profilerDisable() { if (is_string(self::$profiler)) { $p = self::$profiler.'_disable'; return $p(); } elseif (is_array(self::$profiler)) { return self::$profiler; } else { return array(); } } private static function profilerWrite($disable, $chunk = '') { set_error_handler('var_dump', 0); $e = error_reporting(81); $data = self::profilerDisable(); if (!$disable) { self::profilerEnable(); } $h = self::$outputStream; $chunk .= "\n"; $i = 50; // 50 ~= 4Ko chunks // Speed optimized paths if (!$data) { // No-op } elseif ((UPROFILER_FLAGS_CPU & self::$flags) && (UPROFILER_FLAGS_MEMORY & self::$flags)) { foreach ($data as $k => $v) { $chunk .= "{$k}//{$v['ct']} {$v['wt']} {$v['cpu']} {$v['mu']} {$v['pmu']}\n"; if (0 === --$i) { self::fwrite($h, $chunk); $chunk = ''; $i = 50; } } } elseif (UPROFILER_FLAGS_MEMORY & self::$flags) { foreach ($data as $k => $v) { $chunk .= "{$k}//{$v['ct']} {$v['wt']} 0 {$v['mu']} {$v['pmu']}\n"; if (0 === --$i) { self::fwrite($h, $chunk); $chunk = ''; $i = 50; } } } elseif (UPROFILER_FLAGS_CPU & self::$flags) { foreach ($data as $k => $v) { $chunk .= "{$k}//{$v['ct']} {$v['wt']} {$v['cpu']} 0 0\n"; if (0 === --$i) { self::fwrite($h, $chunk); $chunk = ''; $i = 50; } } } else { foreach ($data as $k => $v) { $chunk .= "{$k}//{$v['ct']} {$v['wt']} 0 0 0\n"; if (0 === --$i) { self::fwrite($h, $chunk); $chunk = ''; $i = 50; } } } if (isset($data['main()'])) { $chunk .= "main()//-{$data['main()']['ct']} 0 0 0 0\n"; } $chunk .= "\nrequest-end: ".microtime(true) ."\nrequest-mu: ".memory_get_usage(true) ."\nrequest-pmu: ".memory_get_peak_usage(true) ."\n"; $h = self::fwrite($h, $chunk); error_reporting($e); restore_error_handler(); return $h; } private static function fwrite($stream, $data) { $len = strlen($data); $written = fwrite($stream, $data); if (false !== $written) { while ($written < $len) { fflush($stream); $w = fwrite($stream, substr($data, $written)); $written += $w ?: $len + 1; } if ($written === $len) { return true; } } } /** * @internal */ public static function onError() { return false; // Delegate error handling to the internal handler, but adds a line in profiler's data } /** * @internal */ public static function onException($e) { // Rethrow only, but adds a line in profiler's data if ('xhprof' === self::$profiler && PHP_VERSION_ID >= 50500) { self::profilerWrite(true); // Prevents a crash with XHProf } throw $e; } /** * @internal */ public static function onShutdown() { // Get and write data now so that any later fatal error // do not prevent collecting what we already have. if (!self::$outputStream) { return; } $e = error_get_last(); register_shutdown_function(__CLASS__.'::onShutdownTail'); $extra = array(); foreach (headers_list() as $data) { $data = explode(': ', $data, 2); switch ($data[0]) { case 'X-Powered-By': continue 2; case 'Set-Cookie': $data[1] = preg_replace('/=.+?;/', '=[...];', $data[1]); } $extra[] = implode(': ', $data); } $extra = 'response-headers: '.base64_encode(serialize($extra))."\n" .(function_exists('http_response_code') ? 'response-code: '.http_response_code()."\n" : '') .self::getErrorHandler('error') .self::getErrorHandler('exception'); if (self::$profiler) { if (isset($e['type'])) { switch ($e['type']) { case E_ERROR: case E_PARSE: case E_USER_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_RECOVERABLE_ERROR: $data = explode("\r", $e['message'], 2); $data = explode("\n", $data[0], 2); $data[1] = " in {$e['file']}:{$e['line']}"; $data[0] = str_replace($data[1], '', $data[0]); $extra .= "fatal-error: {$data[0]}{$data[1]}\n"; break; } } } self::profilerWrite(false, $extra); } /** * @internal */ public static function onShutdownTail() { // Cleanup remaining output buffers as much as possible $l = ob_get_level(); while ($l-- && ($s = ob_get_status()) && (!empty($s['del']) || (isset($s['flags']) && ($s['flags'] & PHP_OUTPUT_HANDLER_REMOVABLE))) ) { if (!isset($s['flags']) || ($s['flags'] & PHP_OUTPUT_HANDLER_FLUSHABLE)) { ob_end_flush(); } elseif ($s['flags'] & PHP_OUTPUT_HANDLER_CLEANABLE) { ob_end_clean(); } else { break; } } ob_start(__CLASS__.'::onEnd', 4096); } /** * @internal */ public static function onEnd($buffer, $mode) { if (PHP_OUTPUT_HANDLER_END & $mode) { if (self::profilerWrite(true)) { stream_is_local(self::$outputStream) and flock(self::$outputStream, LOCK_UN); fclose(self::$outputStream); } } return $buffer; }}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.006 0.009 16.37 8.3.5 0.011 0.010 22.93 8.3.4 0.004 0.011 18.67 8.3.3 0.010 0.003 18.79 8.3.2 0.004 0.004 20.34 8.3.1 0.008 0.000 21.77 8.3.0 0.005 0.003 17.63 8.2.18 0.007 0.010 18.29 8.2.17 0.007 0.011 22.96 8.2.16 0.010 0.010 20.39 8.2.15 0.004 0.004 24.18 8.2.14 0.005 0.003 24.66 8.2.13 0.003 0.010 26.16 8.2.12 0.005 0.003 21.02 8.2.11 0.000 0.009 22.14 8.2.10 0.006 0.006 19.38 8.2.9 0.004 0.004 19.09 8.2.8 0.008 0.000 17.97 8.2.7 0.006 0.003 17.25 8.2.6 0.002 0.005 17.80 8.2.5 0.003 0.006 18.07 8.2.4 0.000 0.008 18.03 8.2.3 0.003 0.005 17.84 8.2.2 0.004 0.004 17.59 8.2.1 0.000 0.007 17.84 8.2.0 0.007 0.000 17.65 8.1.28 0.011 0.007 25.92 8.1.27 0.004 0.004 22.14 8.1.26 0.007 0.000 26.35 8.1.25 0.004 0.004 28.09 8.1.24 0.011 0.000 23.84 8.1.23 0.009 0.003 19.15 8.1.22 0.000 0.008 17.74 8.1.21 0.005 0.003 18.77 8.1.20 0.000 0.009 17.25 8.1.19 0.005 0.005 16.98 8.1.18 0.005 0.003 18.10 8.1.17 0.003 0.008 18.26 8.1.16 0.007 0.000 21.98 8.1.15 0.005 0.002 18.77 8.1.14 0.005 0.003 17.25 8.1.13 0.000 0.007 17.82 8.1.12 0.004 0.004 17.43 8.1.11 0.003 0.005 17.25 8.1.10 0.000 0.007 17.33 8.1.9 0.003 0.005 17.41 8.1.8 0.000 0.007 17.36 8.1.7 0.007 0.000 17.29 8.1.6 0.004 0.004 17.37 8.1.5 0.000 0.008 17.48 8.1.4 0.008 0.000 17.47 8.1.3 0.003 0.005 17.45 8.1.2 0.009 0.000 17.46 8.1.1 0.000 0.009 17.38 8.1.0 0.003 0.005 17.29 8.0.30 0.002 0.005 18.77 8.0.29 0.000 0.007 16.63 8.0.28 0.003 0.003 18.46 8.0.27 0.003 0.003 17.35 8.0.26 0.007 0.000 17.15 8.0.25 0.003 0.003 16.76 8.0.24 0.000 0.007 16.86 8.0.23 0.007 0.000 16.80 8.0.22 0.000 0.007 16.69 8.0.21 0.003 0.003 16.71 8.0.20 0.000 0.006 16.84 8.0.19 0.004 0.004 16.75 8.0.18 0.000 0.008 16.86 8.0.17 0.008 0.000 16.79 8.0.16 0.004 0.004 16.77 8.0.15 0.000 0.007 16.81 8.0.14 0.003 0.006 16.62 8.0.13 0.003 0.003 13.40 8.0.12 0.000 0.008 16.81 8.0.11 0.004 0.004 16.77 8.0.10 0.004 0.004 16.74 8.0.9 0.007 0.000 16.70 8.0.8 0.004 0.012 16.86 8.0.7 0.005 0.003 16.68 8.0.6 0.000 0.007 16.91 8.0.5 0.000 0.007 16.81 8.0.3 0.014 0.012 16.97 8.0.2 0.014 0.008 17.40 8.0.1 0.000 0.007 16.84 8.0.0 0.012 0.006 16.77 7.4.33 0.005 0.000 15.08 7.4.32 0.003 0.003 16.48 7.4.30 0.000 0.007 16.42 7.4.29 0.011 0.000 16.51 7.4.28 0.000 0.008 16.39 7.4.27 0.003 0.003 16.32 7.4.26 0.000 0.007 16.48 7.4.25 0.004 0.004 16.47 7.4.24 0.002 0.005 16.46 7.4.23 0.007 0.000 16.59 7.4.22 0.007 0.010 16.37 7.4.21 0.007 0.007 16.43 7.4.20 0.003 0.003 16.29 7.4.16 0.009 0.006 16.45 7.4.15 0.012 0.012 17.40 7.4.14 0.011 0.006 17.86 7.4.13 0.007 0.011 16.56 7.4.12 0.012 0.006 16.36 7.4.11 0.006 0.010 16.63 7.4.10 0.006 0.012 16.25 7.4.9 0.010 0.007 16.52 7.4.8 0.009 0.009 19.39 7.4.7 0.011 0.011 16.39 7.4.6 0.003 0.014 16.55 7.4.5 0.003 0.003 16.25 7.4.4 0.008 0.008 16.55 7.4.3 0.008 0.008 16.51 7.3.33 0.003 0.003 13.28 7.3.32 0.006 0.000 12.92 7.3.31 0.004 0.004 16.06 7.3.30 0.000 0.007 16.14 7.3.29 0.011 0.003 16.12 7.3.28 0.012 0.006 16.16 7.3.27 0.010 0.010 17.40 7.3.26 0.014 0.009 16.20 7.3.24 0.011 0.011 16.46 7.3.23 0.012 0.006 16.39 7.3.21 0.015 0.009 16.34 7.3.20 0.000 0.018 19.39 7.3.19 0.015 0.006 16.20 7.3.18 0.010 0.007 16.39 7.3.17 0.012 0.004 16.27 7.3.16 0.015 0.000 16.31 7.2.33 0.010 0.007 16.45 7.2.32 0.007 0.011 16.23 7.2.31 0.003 0.016 16.69 7.2.30 0.007 0.011 16.55 7.2.29 0.000 0.016 16.29 5.4.32 0.012 0.041 12.48 5.4.31 0.009 0.035 12.49 5.4.30 0.009 0.040 12.50 5.4.29 0.005 0.050 12.48 5.4.28 0.006 0.035 12.39 5.4.27 0.008 0.033 12.38 5.4.26 0.004 0.041 12.38 5.4.25 0.008 0.039 12.39 5.4.24 0.007 0.041 12.38 5.4.23 0.005 0.040 12.37 5.4.22 0.004 0.040 12.37 5.4.21 0.006 0.035 12.37 5.4.20 0.005 0.051 12.37 5.4.19 0.006 0.045 12.37 5.4.18 0.010 0.041 12.37 5.4.17 0.011 0.036 12.38 5.4.16 0.009 0.041 12.37 5.4.15 0.006 0.042 12.37 5.4.14 0.007 0.038 12.05 5.4.13 0.004 0.041 12.04 5.4.12 0.007 0.041 12.00 5.4.11 0.010 0.031 11.99 5.4.10 0.009 0.038 12.00 5.4.9 0.007 0.040 11.99 5.4.8 0.006 0.039 12.00 5.4.7 0.008 0.037 11.99 5.4.6 0.010 0.036 11.99 5.4.5 0.006 0.047 11.99 5.4.4 0.006 0.035 11.98 5.4.3 0.007 0.042 11.98 5.4.2 0.008 0.039 11.97 5.4.1 0.007 0.041 11.98 5.4.0 0.005 0.042 11.47
preferences:dark mode live preview
34.52 ms | 401 KiB | 5 Q