Using tideways_ Xhprof + xhgui analysis of PHP execution

  • preparation in advance

    1. Installing the tideways extension

      For details, see -xhprof-ext…

      Generating PHP execution data depends on this extension

    2. Pull xhgui project to display the data generated above

      This project relies on mongodb, so you also need to install mongodb and the corresponding PHP extension

  • to configure

    There are two ways to configure the header.php The file is relatively simple, the configuration is used without modifying the code, but the code of CLI mode cannot use this method

    • You can directly import the header file of xhgui

      Add to nginx or Apache configuration


      After the introduction, you can directly access the target URL, and then view the xhgui

    • Manual configuration

      1. Add before the code that needs to be analyzed


        The document does not use parameters. In the analysis data without parameters, there is only CT wt data, and there is no memory. When xhgui is displayed, an error will be reported, so the corresponding parameter configuration needs to be added

      2. Add after code execution

          $xhprofData['profile'] = tideways_xhprof_disable();
          $time = time();
          $requestTs = array('sec' => $time, 'usec' => 0);
          $requestTsMicro = array('sec' => 0, 'usec' => 0);
          $xhprofData['meta'] = array(
            'url' => "",
            'SERVER' => $_SERVER,
            'get' => $_GET,
            'env' => $_ENV,
            'simple_url' => "",
            'request_ts' => $requestTs,
            'request_ts_micro' => $requestTsMicro,
            'request_date' => date('Y-m-d', $time),

        Write analysis data in rows.

        Because you want to import data into xhgui, you need to import data according to the data format of xhgui. Otherwise, xhgui will not display normally. The above format is the data assembled by xhgui format

      3. Import the JSON file generated above into xhgui database

        By executing xhgui’s import.php To import, you need to configure Mongo of xhgui before importing

          php /var/www/xhgui/external/import.php -f ./myapplication.xhprof

        Now you can go to xhgui to view the data