Tideways的安裝和使用:https://success.blog.csdn.net/article/details/103365063
static關鍵字實現單例模式:https://success.blog.csdn.net/article/details/103718450
函數代碼:
if (!function_exists('tideways')){
function &tideways($begin = true, $file = '', $dir = '/tmp/')
{
static $data = [];
if ($begin){
extension_loaded('tideways_xhprof');
tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_CPU | TIDEWAYS_XHPROF_FLAGS_MEMORY);
$data['begin'] = microtime(true);
}else{
$data['end'] = microtime(true);
$dir = sprintf('%s%s-%s.log', $dir, $file, date('Y-m-d', time()));
$content = json_encode(tideways_xhprof_disable());
file_put_contents($dir, $content);
}
return $data;
}
}
使用代碼
tideways(true);
run code ......
tideways(false, substr(basename(__FILE__), 0, -4));