register_shutdown_function函数无效是什么原因?

<?php
xhprof_enable(
    XHPROF_FLAGS_MEMORY|XHPROF_FLAGS_CPU,
    [
        'ignored_functions'    => [
            'call_user_func',
            'call_user_func_array'
        ]
    ]
);
//在程序结束后收集数据
register_shutdown_function(function() {
    $xhprof_data        = xhprof_disable();

    //让数据收集程序在后台运行
    if (function_exists('fastcgi_finish_request')) {
        fastcgi_finish_request();
    }

    //保存xhprof数据
    require './xhprof/xhprof_lib/utils/xhprof_lib.php';
    require './xhprof/xhprof_lib/utils/xhprof_runs.php';

    $xhprofRuns = new XHProfRuns_Default();
    $runId = $xhprofRuns->save_run($xhprof_data, 'xhprof_test');

    echo 'http://localhost/thinkphp/public/xhprof/xhprof_html/index.php?run=' . $runId . '&source=xhprof_test';
});
/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

这样用无效,我现在只能手动把那段回调函数放在文件的最后一行。

阅读 4.1k
3 个回答

xhprof_enable函数放在register_shutdown_function回调函数内末尾?

猜测是程序已经执行完,所有的变量数据都已经被回收释放,回调函数里,xhprof_disable已经拿不到上文的日志数据了,所以像是没有执行register_shutdown_function的感觉

你随便用程序创建个文件看看有没有走

推荐问题