github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/ddevapp/dotddev_assets/xhprof/xhprof_prepend.php (about) 1 <?php 2 3 // #ddev-generated 4 // If you want to take over and customize this file, remove the line above 5 // And check this file in. 6 7 // This file is used by `ddev xhprof on` and determines the behavior 8 // of xhprof when it is enabled. It is mounted into the ddev-webserver container 9 // as /usr/local/bin/xhprof/xhprof_prepend.php 10 11 // It can be customized for particular sites or for particular CMS versions. 12 // Some suggestions and examples are provided below. 13 14 $uri = "none"; 15 if (!empty($_SERVER) && array_key_exists('REQUEST_URI', $_SERVER)) { 16 $uri = $_SERVER['REQUEST_URI']; 17 } 18 19 // Enable xhprof profiling if we're not on an xhprof page 20 if (extension_loaded('xhprof') && strpos($uri, '/xhprof') === false) { 21 // If this is too much information, just use xhprof_enable(), which shows CPU only 22 xhprof_enable(XHPROF_FLAGS_MEMORY); 23 register_shutdown_function('xhprof_completion'); 24 } 25 26 // Write to the xhprof_html output and latest on completion 27 function xhprof_completion() 28 { 29 $xhprof_link_dir = "/var/xhprof/xhprof_html/latest/"; 30 31 $xhprof_data = xhprof_disable(); 32 $appNamespace = "ddev"; 33 include_once '/var/xhprof/xhprof_lib/utils/xhprof_lib.php'; 34 include_once '/var/xhprof/xhprof_lib/utils/xhprof_runs.php'; 35 36 $xhprof_runs = new XHProfRuns_Default(); 37 $run_id = $xhprof_runs->save_run($xhprof_data, $appNamespace); 38 39 // Uncomment to append profile link to the page (and remove the ddev generated first line) 40 // append_profile_link($run_id, $appNamespace); 41 } 42 43 // If invoked, this will append a profile link to the output HTML 44 // This works on some CMSs, like Drupal 7. It does not work on Drupal8/9 45 // and can have unwanted side-effects on TYPO3 46 function append_profile_link($run_id, $appNamespace) 47 { 48 $base_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]/xhprof/"; 49 50 $profiler_url = sprintf('%sindex.php?run=%s&source=%s', $base_link, $run_id, $appNamespace); 51 echo '<div id="xhprof"><a href="' . $profiler_url . '" target="_blank">xhprof profiler output</a></div>'; 52 }