Skip to content

Instantly share code, notes, and snippets.

@sylvainraye
Created November 26, 2016 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sylvainraye/c2172be9c1000d5fba72bdf12eb69564 to your computer and use it in GitHub Desktop.
Save sylvainraye/c2172be9c1000d5fba72bdf12eb69564 to your computer and use it in GitHub Desktop.
XHProf for index.php for Magento 1.x
<?php
/**
* Magento Enterprise Edition
*
* NOTICE OF LICENSE
*
* This source file is subject to the Magento Enterprise Edition End User License Agreement
* that is bundled with this package in the file LICENSE_EE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.magento.com/license/enterprise-edition
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
* @license http://www.magento.com/license/enterprise-edition
*/
if (version_compare(phpversion(), '5.3.0', '<')===true) {
echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.3.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
Magento using PHP-CGI as a work-around.</p></div>';
exit;
}
/**
* Compilation includes configuration file
*/
define('MAGENTO_ROOT', getcwd());
$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
include $compilerConfig;
}
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';
if (!file_exists($mageFilename)) {
if (is_dir('downloader')) {
header("Location: downloader");
} else {
echo $mageFilename." was not found";
}
exit;
}
$ignoreIps = [];
$isDeveloper = true;
if ((!isset($_SERVER["HTTP_X_FORWARDED_FOR"]) || !in_array($_SERVER["HTTP_X_FORWARDED_FOR"], $ignoreIps))
&& !in_array($_SERVER["REMOTE_ADDR"], $ignoreIps)) {
$isDeveloper = false;
}
if (file_exists($maintenanceFile)) {
if ($isDeveloper) {
include_once dirname(__FILE__) . '/errors/503.php';
exit;
}
}
require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE']) || $isDeveloper) {
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
// Varien_Profiler::enable();
if (function_exists('xhprof_enable')) {
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS);
}
}
umask(0);
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::run($mageRunCode, $mageRunType);
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE']) && function_exists('xhprof_disable')) {
// stop profiler
$xhprof_data = xhprof_disable();
// display raw xhprof data for the profiler run
//print_r($xhprof_data);
//$XHPROF_ROOT = realpath(dirname(__FILE__));
$XHPROF_ROOT = '.';
if (file_exists($XHPROF_ROOT . "/xhprof/xhprof_lib/utils/xhprof_lib.php")) {
require_once $XHPROF_ROOT . "/xhprof/xhprof_lib/utils/xhprof_lib.php";
require_once $XHPROF_ROOT . "/xhprof/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_magento");
echo "---------------\n".
"Assuming you have set up the http based UI for \n".
"XHProf at some address, you can view run at \n".
"<a href='http://mydomain.dev/xhprof/xhprof_html/index.php?run=$run_id&source=xhprof_magento'>http://mydomain.dev/xhprof/xhprof_html/index.php?run=$run_id&source=xhprof_magento</a>\n".
"---------------\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment