83 行
3.6 KiB
PHP
83 行
3.6 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Config;
|
||
use think\Route;
|
||
|
||
/**
|
||
* 路由诊断探针(临时,验证完成后删除)
|
||
* 访问:GET /api/probe/index
|
||
*/
|
||
class Probe extends \app\common\controller\Api
|
||
{
|
||
protected $noNeedLogin = ['*'];
|
||
protected $noNeedRight = ['*'];
|
||
|
||
public function index()
|
||
{
|
||
// TP5.0 无 Route::getRules(),用反射读取静态 $rules
|
||
$ref = new \ReflectionClass(Route::class);
|
||
$prop = $ref->getProperty('rules');
|
||
$prop->setAccessible(true);
|
||
$rules = $prop->getValue();
|
||
|
||
$getBucket = isset($rules['get']) ? $rules['get'] : [];
|
||
$starBucket = isset($rules['*']) ? $rules['*'] : [];
|
||
|
||
$out = [
|
||
'request_path' => $this->request->path(),
|
||
'request_pathinfo' => $this->request->pathinfo(),
|
||
'request_module' => $this->request->module(),
|
||
'request_controller' => $this->request->controller(),
|
||
'request_action' => $this->request->action(),
|
||
'server_PATH_INFO' => isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null,
|
||
'get_s' => isset($_GET['s']) ? $_GET['s'] : null,
|
||
'url_route_on' => Config::get('url_route_on'),
|
||
'route_config_file' => Config::get('route_config_file'),
|
||
'pathinfo_depr' => Config::get('pathinfo_depr'),
|
||
'CONF_PATH' => CONF_PATH,
|
||
'route_file_exists' => is_file(CONF_PATH . 'route.php'),
|
||
'runtime_route_file' => is_file(RUNTIME_PATH . 'route.php'),
|
||
'rule_buckets' => array_keys($rules),
|
||
'get_bucket_count' => count($getBucket),
|
||
'star_bucket_count' => count($starBucket),
|
||
'get_sample' => array_slice(array_keys($getBucket), 0, 8),
|
||
'has_static_rule' => isset($getBucket['api/v1/home/banners']),
|
||
'star_has_static' => isset($starBucket['api/v1/home/banners']),
|
||
];
|
||
|
||
// —— 追加:文件真实内容 & OPcache 取证 ——
|
||
$rf = CONF_PATH . 'route.php';
|
||
$out['route_file_realpath'] = is_file($rf) ? realpath($rf) : null;
|
||
$out['route_file_size'] = is_file($rf) ? filesize($rf) : -1;
|
||
$out['route_file_mtime'] = is_file($rf) ? date('c', filemtime($rf)) : null;
|
||
$loaded = is_file($rf) ? include $rf : null;
|
||
$out['included_is_array'] = is_array($loaded);
|
||
$out['included_rule_count'] = is_array($loaded) ? count($loaded) : -1;
|
||
$out['included_keys'] = is_array($loaded) ? array_slice(array_keys($loaded), 0, 4) : null;
|
||
|
||
$out['opcache_enabled'] = function_exists('opcache_get_status') ? (bool)@opcache_get_status(false)['opcache_enabled'] : null;
|
||
$out['ini_validate_ts'] = ini_get('opcache.validate_timestamps');
|
||
$out['ini_revalidate'] = ini_get('opcache.revalidate_freq');
|
||
$out['ini_opcache_on'] = ini_get('opcache.enable');
|
||
if (function_exists('opcache_get_status')) {
|
||
$st = @opcache_get_status(true);
|
||
if (!empty($st['scripts'])) {
|
||
foreach ($st['scripts'] as $path => $info) {
|
||
if (strpos($path, '/application/route.php') !== false) {
|
||
$out['opcache_cached_route'] = [
|
||
'path' => $path,
|
||
'timestamp' => date('c', $info['timestamp']),
|
||
'hits' => $info['hits'],
|
||
];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
echo json_encode($out, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||
exit;
|
||
}
|
||
}
|