Skip to content

Instantly share code, notes, and snippets.

@dshafik
Created November 24, 2011 16:38
Show Gist options
  • Save dshafik/1391756 to your computer and use it in GitHub Desktop.
Save dshafik/1391756 to your computer and use it in GitHub Desktop.
diff --git a/external/footer.php b/external/footer.php
index 0bd5e30..c6fa5da 100755
--- a/external/footer.php
+++ b/external/footer.php
@@ -4,7 +4,7 @@ if (extension_loaded('xhprof') && $_xhprof['doprofile'] === true) {
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace, null, $_xhprof);
- if ($_xhprof['display'] === true)
+ if ($_xhprof['display'] === true && PHP_SAPI != 'cli')
{
// url to the XHProf UI libraries (change the host name and path)
$profiler_url = sprintf($_xhprof['url'].'/index.php?run=%s&source=%s', $run_id, $profiler_namespace);
diff --git a/external/header.php b/external/header.php
index 7dc4c12..27a4ffc 100755
--- a/external/header.php
+++ b/external/header.php
@@ -1,4 +1,9 @@
<?php
+if (PHP_SAPI == 'cli') {
+ $_SERVER['REMOTE_ADDR'] = null;
+ $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
+}
+
include(dirname(__FILE__) . '/..//xhprof_lib/config.php');
//I'm Magic :)
@@ -26,7 +31,7 @@ class visibilitator
}
// Only users from authorized IP addresses may control Profiling
-if ($controlIPs === false || in_array($_SERVER['REMOTE_ADDR'], $controlIPs))
+if ($controlIPs === false || in_array($_SERVER['REMOTE_ADDR'], $controlIPs) || PHP_SAPI == 'cli')
{
if (isset($_GET['_profile']))
{
@@ -37,7 +42,7 @@ if ($controlIPs === false || in_array($_SERVER['REMOTE_ADDR'], $controlIPs))
exit;
}
- if (isset($_COOKIE['_profile']) && $_COOKIE['_profile'])
+ if (isset($_COOKIE['_profile']) && $_COOKIE['_profile'] || PHP_SAPI == 'cli' && ((isset($_SERVER['XHPROF_PROFILE']) && $_SERVER['XHPROF_PROFILE']) || (isset($_ENV['XHPROF_PROFILE']) && $_ENV['XHPROF_PROFILE'])))
{
$_xhprof['display'] = true;
$_xhprof['doprofile'] = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment