mdserver-web/plugins/php/conf/app_start.php

57 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2020-07-12 06:15:03 -04:00
<?php
2024-12-13 10:10:04 -05:00
if (isset($_GET['mw_opcache_reset']) && $_GET['mw_opcache_reset'] == 'ok') {
2024-12-13 11:19:32 -05:00
if (function_exists('opcache_reset')) {
opcache_reset();
}
2024-01-25 02:38:32 -05:00
}
2020-07-12 06:15:03 -04:00
define('XHProf_Name', 'mdd');
/**
* xhprof 配置,便于调试快速找到问题
*/
2022-09-20 04:32:11 -04:00
2020-07-12 06:15:03 -04:00
function app_xhprof_start() {
2024-12-13 10:10:04 -05:00
$root = '{$ROOT_PATH}';
$lib = $root . '/server/xhprof/xhprof_lib/utils/xhprof_lib.php';
if (file_exists($lib)) {
include_once $lib;
include_once $root . '/server/xhprof/xhprof_lib/utils/xhprof_runs.php';
xhprof_enable();
}
2020-07-12 06:15:03 -04:00
}
function app_xhprof_end() {
2024-12-13 10:10:04 -05:00
$root = '{$ROOT_PATH}';
$lib = $root . '/server/xhprof';
if (! file_exists($lib)) {
return;
}
2020-07-12 06:15:03 -04:00
2024-12-13 10:10:04 -05:00
//保存xhprof数据
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
2020-07-12 06:15:03 -04:00
2024-12-13 10:10:04 -05:00
$run_id = $xhprof_runs->save_run($xhprof_data, 'xhprof_foo');
2020-07-12 06:15:03 -04:00
2024-12-13 10:10:04 -05:00
$profiler_url = sprintf('http://{$LOCAL_IP}:5858/index.php?run=%s&source=xhprof_foo', $run_id);
2024-12-13 10:19:00 -05:00
// echo "<script language='javascript'>window.open('{$profiler_url}')</script>";
2024-12-13 10:28:48 -05:00
2024-12-13 10:36:16 -05:00
$style_css = 'position:fixed;bottom: 0px;right: 0px;z-index: 100000000;color: red;background-color: black;padding: 0px;margin: 0px;';
2024-12-13 10:28:48 -05:00
echo '<a href="' . $profiler_url . '" target="_blank" style="' . $style_css . '">XHProf分析结果</a>';
2020-07-12 06:15:03 -04:00
}
if (extension_loaded('xhprof')
2024-12-13 10:10:04 -05:00
&& isset($_GET[XHProf_Name]) && $_GET[XHProf_Name] == 'ok' &&
2025-01-03 23:59:22 -05:00
(! in_array($_SERVER['SCRIPT_NAME'], array('/xhprof_html/callgraph.php','/xhprof_html/index.php')))) {
2024-12-13 10:10:04 -05:00
app_xhprof_start();
register_shutdown_function('app_xhprof_end');
include_once $_SERVER['SCRIPT_FILENAME'];
2024-12-13 13:21:31 -05:00
exit;
2020-07-12 06:15:03 -04:00
}
?>