github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/containers/ddev-webserver/ddev-webserver-base-files/usr/local/bin/xhprof/xhprof_prepend.php (about)

     1  <?php
     2  
     3  // This file is built into the container and will normally be
     4  // mounted on top of by ddev. So you shouldn't be seeing these words.
     5  
     6  $uri = "none";
     7  if (!empty($_SERVER) && array_key_exists('REQUEST_URI', $_SERVER)) {
     8    $uri = $_SERVER['REQUEST_URI'];
     9  }
    10  
    11  // Enable xhprof profiling if we're not on an xhprof page
    12  if (extension_loaded('xhprof') && strpos($uri, '/xhprof') === false) {
    13    // If this is too much information, just use xhprof_enable(), which shows CPU only
    14    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
    15    register_shutdown_function('xhprof_completion');
    16  }
    17  
    18  // Write to the xhprof_html output and latest on completion
    19  function xhprof_completion()
    20  {
    21    $xhprof_link_dir = "/var/xhprof/xhprof_html/latest/";
    22  
    23    $xhprof_data = xhprof_disable();
    24    $appNamespace = "ddev";
    25    include_once '/var/xhprof/xhprof_lib/utils/xhprof_lib.php';
    26    include_once '/var/xhprof/xhprof_lib/utils/xhprof_runs.php';
    27  
    28    $xhprof_runs = new XHProfRuns_Default();
    29    $run_id = $xhprof_runs->save_run($xhprof_data, $appNamespace);
    30  
    31    // Uncomment to append profile link to the page (and remove the ddev generated first line)
    32    // append_profile_link($run_id, $appNamespace);
    33  }
    34  
    35  // If invoked, this will append a profile link to the output HTML
    36  // This works on some CMSs, like Drupal 7. It does not work on Drupal8/9
    37  // and can have unwanted side-effects on TYPO3
    38  function append_profile_link($run_id, $appNamespace)
    39  {
    40    $base_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]/xhprof/";
    41  
    42    $profiler_url = sprintf('%sindex.php?run=%s&amp;source=%s', $base_link, $run_id, $appNamespace);
    43    echo '<div id="xhprof"><a href="' . $profiler_url . '" target="_blank">xhprof profiler output</a></div>';
    44  }