longxinH / xhprof

PHP7/PHP8 support
http://pecl.php.net/package/xhprof
Apache License 2.0
1.09k stars 167 forks source link

分析laravel性能出现错误 #13

Closed toxmc closed 6 years ago

toxmc commented 6 years ago

通过非侵入式方式开启监控

<?php
if (isset($_GET['xhprof']) && $_GET['xhprof']) {
    //开启xhprof
    xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU);

    //在程序结束后收集数据
    register_shutdown_function(function() {
        $xhprof_data = xhprof_disable();

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

        //保存xhprof数据
        $XHPROF_ROOT = '/Users/xmc/php/xhprof';
        include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
        include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
        // save raw data for this profiler run using default
        // implementation of iXHProfRuns.
        $xhprof_runs = new XHProfRuns_Default();
        // save the run under a namespace "xhprof_foo"
        $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
    });
}

报错

2018/08/02 13:52:24 [error] 78653#0: *15802 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined property: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::$REQUEST_TIME in /Users/xmc/PhpstormProjects/test/api/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php on line 73
PHP message: PHP Notice:  Undefined property: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::$REQUEST_TIME in /Users/xmc/PhpstormProjects/test/api/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php on line 73
PHP message: PHP Notice:  Undefined property: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::$REQUEST_TIME in /Users/xmc/PhpstormProjects/test/api/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php on line 73
PHP message: PHP Notice:  Undefined property: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::$REQUEST_TIME in /Users/xmc/PhpstormProjects/test/api/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php on line 73
PHP message: PHP Notice:  Undefined property: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::$REQUEST_TIME in /Users/xmc/PhpstormProjects/test/api/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php on line 73
PHP message: PHP Notice:  Undefined property: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::$REQUEST_TIME in /Users/xmc/PhpstormProjects/test/api/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php on line 73
PHP message: PHP Notice:  Undefined property: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::$REQUEST_TIME in /Users/xmc/PhpstormProjects/test/api/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php on line 73

去掉监控部分则执行正常。 Mac PHP 7.1.14 laravel 5.5

longxinH commented 6 years ago

你能不能提供简单重现的例子,laravel没接触过,简单的部署了一下没能重现

toxmc commented 6 years ago

laravel 项目上引用了很多包,加上业务代码比较复杂,具体那个导致的不太好给重现的例子。警告不影响使用就是了

cnBruceHong commented 6 years ago

@toxmc 你这段代码是在哪个地方插入的

toxmc commented 6 years ago

@cnBruceHong nginx中通过

 location ~ \.php$ {
            root           /Users/xmc/work/php/xhprof;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param PHP_VALUE "auto_prepend_file=/Users/xmc/work/php/xhprof/inject.php"; 
            include        fastcgi_params;
        }