├── .gitignore ├── source ├── glimpse.ini ├── resources │ ├── logo.png │ └── sprite.png ├── Glimpse │ ├── Store │ │ ├── Interface.php │ │ └── File.php │ ├── Handler │ │ ├── Interface.php │ │ ├── Data.php │ │ ├── Clients.php │ │ ├── EmbeddedResource.php │ │ ├── History.php │ │ └── Config.php │ ├── Plugin │ │ ├── Interface.php │ │ ├── Environment.php │ │ ├── Server.php │ │ ├── Config.php │ │ ├── Session.php │ │ ├── Trace.php │ │ ├── Plugins.php │ │ └── Request.php │ ├── AutoLoader.php │ └── Trace.php ├── index.php └── Glimpse.php ├── samples └── index.php └── README.markdown /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/ 2 | /.buildpath 3 | /.project 4 | -------------------------------------------------------------------------------- /source/glimpse.ini: -------------------------------------------------------------------------------- 1 | [Glimpse] 2 | ;plugins-disabled=Glimpse_Plugin_Trace -------------------------------------------------------------------------------- /source/resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlimpseArchive/Glimpse.PHP/HEAD/source/resources/logo.png -------------------------------------------------------------------------------- /source/resources/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlimpseArchive/Glimpse.PHP/HEAD/source/resources/sprite.png -------------------------------------------------------------------------------- /samples/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |This is just a test.
11 | 12 | 13 | -------------------------------------------------------------------------------- /source/Glimpse/Store/Interface.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | interface Glimpse_Store_Interface 8 | { 9 | /** 10 | * Store data. 11 | * 12 | * @param mixed $data Data to store. 13 | */ 14 | function store($data = ''); 15 | 16 | /** 17 | * Fetch data. 18 | * 19 | * @return mixed Data retrieved from store. 20 | */ 21 | function fetch(); 22 | } -------------------------------------------------------------------------------- /source/Glimpse/Handler/Interface.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | interface Glimpse_Handler_Interface 8 | { 9 | /** 10 | * Processes the handler pre-run. 11 | * 12 | * @param Glimpse $glimpse The current Glimpse instance. 13 | * @return string The rendered handler. 14 | */ 15 | function processPreRun(Glimpse $glimpse); 16 | 17 | /** 18 | * Processes the handler post-run. 19 | * 20 | * @param Glimpse $glimpse The current Glimpse instance. 21 | * @return string The rendered handler. 22 | */ 23 | function processPostRun(Glimpse $glimpse); 24 | } -------------------------------------------------------------------------------- /source/Glimpse/Plugin/Interface.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | interface Glimpse_Plugin_Interface 10 | { 11 | /** 12 | * Gets the plugin data that should be rendered on the output protocol stream. 13 | * 14 | * @param Glimpse $glimpse The current Glimpse instance. 15 | * @return array Array conforming to the Glimpse protocol definition. 16 | */ 17 | function getData(Glimpse $glimpse); 18 | 19 | /** 20 | * Get the plugin help URL. 21 | * 22 | * @return string Help URL for the plugin. 23 | */ 24 | function getHelpUrl(); 25 | } -------------------------------------------------------------------------------- /source/index.php: -------------------------------------------------------------------------------- 1 | $glimpseBaseDir 11 | ); 12 | 13 | // Read configuration 14 | $glimpseConfigurationFile = dirname(str_replace('phar://', '', $glimpseBaseDir) . '/glimpse') . '/glimpse.ini'; 15 | if (file_exists($glimpseConfigurationFile)) { 16 | $configuration = parse_ini_file($glimpseConfigurationFile, true); 17 | $glimpseConfiguration = array_merge($glimpseConfiguration, $configuration['Glimpse']); 18 | } 19 | 20 | // Start Glimpse 21 | $glimpse = new Glimpse($glimpseConfiguration); -------------------------------------------------------------------------------- /source/Glimpse/Plugin/Environment.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | class Glimpse_Plugin_Environment 10 | implements Glimpse_Plugin_Interface 11 | { 12 | /** 13 | * Gets the plugin data that should be rendered on the output protocol stream. 14 | * 15 | * @param Glimpse $glimpse The current Glimpse instance. 16 | * @return array Array conforming to the Glimpse protocol definition. 17 | */ 18 | public function getData(Glimpse $glimpse) { 19 | $info = $glimpse->retrievePhpInfo(); 20 | $data = $info["Environment"]; 21 | return array( 22 | "Environment" => count($data) > 0 ? $data : null 23 | ); 24 | } 25 | 26 | /** 27 | * Get the plugin help URL. 28 | * 29 | * @return string Help URL for the plugin. 30 | */ 31 | public function getHelpUrl() { 32 | return "http://getGlimpse.com/Help/Plugin/Environment"; 33 | } 34 | } -------------------------------------------------------------------------------- /source/Glimpse/Plugin/Server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | class Glimpse_Plugin_Server 10 | implements Glimpse_Plugin_Interface 11 | { 12 | /** 13 | * Gets the plugin data that should be rendered on the output protocol stream. 14 | * 15 | * @param Glimpse $glimpse The current Glimpse instance. 16 | * @return array Array conforming to the Glimpse protocol definition. 17 | */ 18 | public function getData(Glimpse $glimpse) { 19 | $data = array(array('Key', 'Value')); 20 | foreach ($_SERVER as $key => $value) { 21 | $data[] = array($key, $value); 22 | } 23 | 24 | return array( 25 | "Server" => count($data) > 0 ? $data : null 26 | ); 27 | } 28 | 29 | /** 30 | * Get the plugin help URL. 31 | * 32 | * @return string Help URL for the plugin. 33 | */ 34 | public function getHelpUrl() { 35 | return "http://getGlimpse.com/Help/Plugin/Server"; 36 | } 37 | } -------------------------------------------------------------------------------- /source/Glimpse/Plugin/Config.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | class Glimpse_Plugin_Config 10 | implements Glimpse_Plugin_Interface 11 | { 12 | /** 13 | * Gets the plugin data that should be rendered on the output protocol stream. 14 | * 15 | * @param Glimpse $glimpse The current Glimpse instance. 16 | * @return array Array conforming to the Glimpse protocol definition. 17 | */ 18 | public function getData(Glimpse $glimpse) { 19 | $info = $glimpse->retrievePhpInfo(); 20 | $data = $info["PHP Configuration"]; 21 | $data['Loaded extensions'] = get_loaded_extensions(); 22 | $data['Loaded ZEND extensions'] = get_loaded_extensions(true); 23 | 24 | return array( 25 | "Config" => count($data) > 0 ? $data : null 26 | ); 27 | } 28 | 29 | /** 30 | * Get the plugin help URL. 31 | * 32 | * @return string Help URL for the plugin. 33 | */ 34 | public function getHelpUrl() { 35 | return "http://getGlimpse.com/Help/Plugin/Config"; 36 | } 37 | } -------------------------------------------------------------------------------- /source/Glimpse/Plugin/Session.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | class Glimpse_Plugin_Session 10 | implements Glimpse_Plugin_Interface 11 | { 12 | /** 13 | * Gets the plugin data that should be rendered on the output protocol stream. 14 | * 15 | * @param Glimpse $glimpse The current Glimpse instance. 16 | * @return array Array conforming to the Glimpse protocol definition. 17 | */ 18 | public function getData(Glimpse $glimpse) { 19 | $data = array(); 20 | 21 | if (isset($_SESSION) && count($_SESSION) > 0) { 22 | $data[] = array('Key', 'Value'); 23 | foreach ($_SESSION as $key => $value) { 24 | $data = array($key, $value); 25 | } 26 | } 27 | 28 | return array( 29 | "Session" => count($data) > 0 ? $data : null 30 | ); 31 | } 32 | 33 | /** 34 | * Get the plugin help URL. 35 | * 36 | * @return string Help URL for the plugin. 37 | */ 38 | public function getHelpUrl() { 39 | return "http://getGlimpse.com/Help/Plugin/Session"; 40 | } 41 | } -------------------------------------------------------------------------------- /source/Glimpse/Plugin/Trace.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | class Glimpse_Plugin_Trace 10 | implements Glimpse_Plugin_Interface 11 | { 12 | /** 13 | * Gets the plugin data that should be rendered on the output protocol stream. 14 | * 15 | * @param Glimpse $glimpse The current Glimpse instance. 16 | * @return array Array conforming to the Glimpse protocol definition. 17 | */ 18 | public function getData(Glimpse $glimpse) { 19 | $data = array(array('Message', 'Category', 'From First', 'From Last')); 20 | $traceData = Glimpse_Trace::retrieveMessages(); 21 | foreach ($traceData as $traceEntry) { 22 | $traceEntry[] = strtolower($traceEntry[1]); 23 | $data[] = $traceEntry; 24 | } 25 | 26 | return array( 27 | "Trace" => count($data) > 0 ? $data : null 28 | ); 29 | } 30 | 31 | /** 32 | * Get the plugin help URL. 33 | * 34 | * @return string Help URL for the plugin. 35 | */ 36 | public function getHelpUrl() { 37 | return "http://getGlimpse.com/Help/Plugin/Trace"; 38 | } 39 | } -------------------------------------------------------------------------------- /source/Glimpse/Plugin/Plugins.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | class Glimpse_Plugin_Plugins 10 | implements Glimpse_Plugin_Interface 11 | { 12 | /** 13 | * Gets the plugin data that should be rendered on the output protocol stream. 14 | * 15 | * @param Glimpse $glimpse The current Glimpse instance. 16 | * @return array Array conforming to the Glimpse protocol definition. 17 | */ 18 | public function getData(Glimpse $glimpse) { 19 | $data = array(); 20 | 21 | $plugins = $glimpse->retrievePlugins(); 22 | foreach ($plugins as $plugin) { 23 | $reflectedObject = new ReflectionObject($plugin); 24 | $pluginName = basename('/' . str_replace('_', '/', $reflectedObject->getName())); 25 | 26 | $data[$pluginName] = array( 27 | 'helpUrl' => !is_null($plugin->getHelpUrl()) ? $plugin->getHelpUrl() : '' 28 | ); 29 | } 30 | 31 | return array( 32 | "plugins" => $data 33 | ); 34 | } 35 | 36 | /** 37 | * Get the plugin help URL. 38 | * 39 | * @return string Help URL for the plugin. 40 | */ 41 | public function getHelpUrl() { 42 | return null; 43 | } 44 | } -------------------------------------------------------------------------------- /source/Glimpse/AutoLoader.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | class Glimpse_AutoLoader 19 | { 20 | /** 21 | * Registers the autoloader 22 | */ 23 | public static function Register() { 24 | return spl_autoload_register(array('Glimpse_AutoLoader', 'Load')); 25 | } 26 | 27 | /** 28 | * Load a class 29 | * 30 | * @param string $className Class name to load 31 | */ 32 | public static function Load($className){ 33 | if ((class_exists($className)) || (strpos($className, 'Glimpse') === false)) { 34 | return false; 35 | } 36 | 37 | $classFilePath = GLIMPSE_ROOT . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; 38 | 39 | if ((file_exists($classFilePath) === false) || (is_readable($classFilePath) === false)) { 40 | return false; 41 | } 42 | 43 | require($classFilePath); 44 | } 45 | } -------------------------------------------------------------------------------- /source/Glimpse/Handler/Data.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | class Glimpse_Handler_Data 8 | implements Glimpse_Handler_Interface 9 | { 10 | /** 11 | * Processes the handler pre-run. 12 | * 13 | * @param Glimpse $glimpse The current Glimpse instance. 14 | * @return string The rendered handler. 15 | */ 16 | public function processPreRun(Glimpse $glimpse) { 17 | } 18 | 19 | 20 | /** 21 | * Processes the handler post-run. 22 | * 23 | * @param Glimpse $glimpse The current Glimpse instance. 24 | * @return string The rendered handler. 25 | */ 26 | public function processPostRun(Glimpse $glimpse) { 27 | if (!defined('GLIMPSE_RENDERED') && !isset($_REQUEST['glimpseFile'])) { 28 | define('GLIMPSE_RENDERED', true); 29 | 30 | $urlPath = $_SERVER['PHP_SELF'] . '?glimpseVersion=' . $glimpse->getVersion() . '&glimpseFile='; 31 | 32 | echo ''; 36 | echo ''; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /source/Glimpse/Store/File.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | class Glimpse_Store_File 8 | implements Glimpse_Store_Interface 9 | { 10 | protected $_fileName = ''; 11 | 12 | public function __construct($fileName = null) { 13 | if (is_null($fileName)) { 14 | $tmpDir = sys_get_temp_dir(); 15 | if (substr($tmpDir, -1 ) != '/' && substr($tmpDir, -1 ) != '\\') { 16 | $tmpDir .= '/'; 17 | } 18 | 19 | $fileName = $tmpDir . 'glimpsestore' . md5(__FILE__); 20 | } 21 | 22 | $this->_fileName = $fileName; 23 | } 24 | 25 | /** 26 | * Store data. 27 | * 28 | * @param mixed $data Data to store. 29 | */ 30 | public function store($data = '') { 31 | $fp = fopen($this->_fileName, "w"); 32 | 33 | if (flock($fp, LOCK_EX)) { 34 | ftruncate($fp, 0); 35 | fwrite($fp, serialize($data)); 36 | flock($fp, LOCK_UN); 37 | } 38 | 39 | fclose($fp); 40 | } 41 | 42 | /** 43 | * Fetch data. 44 | * 45 | * @return mixed Data retrieved from store. 46 | */ 47 | public function fetch() { 48 | if (!file_exists($this->_fileName)) { 49 | return null; 50 | } 51 | 52 | $fileContents = ''; 53 | 54 | $fp = fopen($this->_fileName, "r"); 55 | if (flock($fp, LOCK_SH)) { 56 | $fileContents = fread($fp, filesize($this->_fileName)); 57 | flock($fp, LOCK_UN); 58 | } 59 | 60 | fclose($fp); 61 | return unserialize($fileContents); 62 | } 63 | } -------------------------------------------------------------------------------- /source/Glimpse/Plugin/Request.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | class Glimpse_Plugin_Request 10 | implements Glimpse_Plugin_Interface 11 | { 12 | /** 13 | * Gets the plugin data that should be rendered on the output protocol stream. 14 | * 15 | * @param Glimpse $glimpse The current Glimpse instance. 16 | * @return array Array conforming to the Glimpse protocol definition. 17 | */ 18 | public function getData(Glimpse $glimpse) { 19 | $data = array(); 20 | 21 | if (isset($_REQUEST) && count($_REQUEST) > 0) { 22 | $data['_REQUEST'] = array(array('Key', 'Value')); 23 | foreach ($_REQUEST as $key => $value) { 24 | $data['_REQUEST'][] = array($key, $value); 25 | } 26 | } 27 | if (isset($_GET) && count($_GET) > 0) { 28 | $data['_GET'] = array(array('Key', 'Value')); 29 | foreach ($_GET as $key => $value) { 30 | $data['_GET'][] = array($key, $value); 31 | } 32 | } 33 | if (isset($_POST) && count($_POST) > 0) { 34 | $data['_POST'] = array(array('Key', 'Value')); 35 | foreach ($_POST as $key => $value) { 36 | $data['_POST'][] = array($key, $value); 37 | } 38 | } 39 | 40 | return array( 41 | "Request" => count($data) > 0 ? $data : null 42 | ); 43 | } 44 | 45 | /** 46 | * Get the plugin help URL. 47 | * 48 | * @return string Help URL for the plugin. 49 | */ 50 | public function getHelpUrl() { 51 | return "http://getGlimpse.com/Help/Plugin/Request"; 52 | } 53 | } -------------------------------------------------------------------------------- /source/Glimpse/Handler/Clients.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | class Glimpse_Handler_Clients 8 | implements Glimpse_Handler_Interface 9 | { 10 | /** 11 | * Processes the handler pre-run. 12 | * 13 | * @param Glimpse $glimpse The current Glimpse instance. 14 | * @return string The rendered handler. 15 | */ 16 | public function processPreRun(Glimpse $glimpse) { 17 | if (!isset($_REQUEST['glimpseFile']) || $_REQUEST['glimpseFile'] != 'Clients') { 18 | return; 19 | } 20 | 21 | // HTTP headers 22 | header('Content-Type: application/json; charset=utf-8'); 23 | 24 | // Build data 25 | $requestHistory = $glimpse->getRequestHistory(); 26 | if (!is_array($requestHistory) || count($requestHistory) == 0) { 27 | echo "{'Error': true, 'Message': 'No history available.'}"; 28 | $glimpse->endRequest(); 29 | } 30 | 31 | $data = array(); 32 | foreach ($requestHistory as $request) { 33 | $data[$request->GlimpseClientName][$request->RequestId] = (object)array( 34 | 'Url' => $request->Url, 35 | 'Browser' => $request->Browser, 36 | 'RequestTime' => $request->RequestTime, 37 | 'IsAjax' => $request->IsAjax, 38 | 'Method' => $request->Method 39 | ); 40 | } 41 | foreach ($data as $key => $value) { 42 | $data[$key] = (object)$value; 43 | } 44 | $data = (object)array('Data' => (object)$data); 45 | 46 | // Return a response 47 | echo json_encode($data); 48 | 49 | $glimpse->endRequest(); 50 | } 51 | 52 | 53 | /** 54 | * Processes the handler post-run. 55 | * 56 | * @param Glimpse $glimpse The current Glimpse instance. 57 | * @return string The rendered handler. 58 | */ 59 | public function processPostRun(Glimpse $glimpse) { 60 | } 61 | } -------------------------------------------------------------------------------- /source/Glimpse/Handler/EmbeddedResource.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | class Glimpse_Handler_EmbeddedResource 8 | implements Glimpse_Handler_Interface 9 | { 10 | /** 11 | * The filename to serve. 12 | * 13 | * @var string 14 | */ 15 | protected $_fileName = null; 16 | 17 | /** 18 | * The content type to serve. 19 | * 20 | * @var string 21 | */ 22 | protected $_contentType = null; 23 | 24 | /** 25 | * Creates a new Glimpse_Handler_EmbeddedResourceHandler instance. 26 | * 27 | * @param string $fileName The filename to serve. 28 | * @param string $contentType The content type to serve. 29 | */ 30 | public function __construct($fileName, $contentType) { 31 | $this->_fileName = $fileName; 32 | $this->_contentType = $contentType; 33 | } 34 | 35 | /** 36 | * Processes the handler pre-run. 37 | * 38 | * @param Glimpse $glimpse The current Glimpse instance. 39 | * @return string The rendered handler. 40 | */ 41 | public function processPreRun(Glimpse $glimpse) { 42 | if (!isset($_REQUEST['glimpseFile'])) { 43 | return; 44 | } 45 | 46 | $file = $_REQUEST['glimpseFile']; 47 | $configuration = $glimpse->retrieveConfiguration(); 48 | $glimpseBaseDir = $configuration['glimpsebasedir']; 49 | $fileToRender = $glimpseBaseDir . '/resources/' . $file; 50 | 51 | if (file_exists($fileToRender)) { 52 | header('Content-Type: ' . $this->_contentType); 53 | echo file_get_contents($fileToRender); 54 | $glimpse->endRequest(); 55 | } 56 | } 57 | 58 | 59 | /** 60 | * Processes the handler post-run. 61 | * 62 | * @param Glimpse $glimpse The current Glimpse instance. 63 | * @param string $file The file to handle. 64 | * @return string The rendered handler. 65 | */ 66 | public function processPostRun(Glimpse $glimpse) { 67 | } 68 | } -------------------------------------------------------------------------------- /source/Glimpse/Handler/History.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | class Glimpse_Handler_History 8 | implements Glimpse_Handler_Interface 9 | { 10 | /** 11 | * Processes the handler pre-run. 12 | * 13 | * @param Glimpse $glimpse The current Glimpse instance. 14 | * @return string The rendered handler. 15 | */ 16 | public function processPreRun(Glimpse $glimpse) { 17 | if (!isset($_REQUEST['glimpseFile']) || $_REQUEST['glimpseFile'] != 'History') { 18 | return; 19 | } 20 | 21 | // HTTP headers 22 | header('Content-Type: application/json; charset=utf-8'); 23 | 24 | // Build data 25 | $requestHistory = $glimpse->getRequestHistory(); 26 | if (!is_array($requestHistory) || count($requestHistory) == 0) { 27 | echo "{'Error': true, 'Message': 'No history available.'}"; 28 | $glimpse->endRequest(); 29 | } 30 | 31 | $data = array(); 32 | if (isset($_REQUEST['ClientRequestId'])) { 33 | foreach ($requestHistory as $request) { 34 | if ($request->RequestId == $_REQUEST['ClientRequestId']) { 35 | $data = (object)array( 36 | 'Data' => json_encode($request->Data) 37 | ); 38 | } 39 | } 40 | } else if (isset($_REQUEST['ClientName'])) { 41 | foreach ($requestHistory as $request) { 42 | if ($_REQUEST['ClientName'] == $request->GlimpseClientName) { 43 | $data[$request->GlimpseClientName][$request->RequestId] = (object)array( 44 | 'Data' => json_encode($request->Data) 45 | ); 46 | } 47 | } 48 | foreach ($data as $key => $value) { 49 | $data[$key] = (object)$value; 50 | } 51 | } 52 | $data = (object)array('Data' => (object)$data); 53 | 54 | // Return a response 55 | echo json_encode($data); 56 | 57 | $glimpse->endRequest(); 58 | } 59 | 60 | 61 | /** 62 | * Processes the handler post-run. 63 | * 64 | * @param Glimpse $glimpse The current Glimpse instance. 65 | * @return string The rendered handler. 66 | */ 67 | public function processPostRun(Glimpse $glimpse) { 68 | } 69 | } -------------------------------------------------------------------------------- /source/Glimpse/Trace.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | class Glimpse_Trace 8 | { 9 | /** 10 | * Trace messages 11 | * 12 | * @var array 13 | */ 14 | private static $_messages = array(); 15 | 16 | /** 17 | * First timing 18 | * 19 | * @var int 20 | */ 21 | private static $_timingFirst = 0; 22 | 23 | /** 24 | * Last timing 25 | * 26 | * @var int 27 | */ 28 | private static $_timingLast = 0; 29 | 30 | /** 31 | * Creates a new Glimpse_Trace instance. 32 | */ 33 | private function __construct() { 34 | } 35 | 36 | /** 37 | * Retrieve log messages. 38 | * 39 | * @return array 40 | */ 41 | public static function retrieveMessages() { 42 | return self::$_messages; 43 | } 44 | 45 | /** 46 | * Logs an Info message to the trace log. 47 | * 48 | * @param string $message Message to log. 49 | */ 50 | public static function info($message = '') { 51 | self::log('Info', $message); 52 | } 53 | 54 | /** 55 | * Logs a Warn message to the trace log. 56 | * 57 | * @param string $message Message to log. 58 | */ 59 | public static function warn($message = '') { 60 | self::log('Warn', $message); 61 | } 62 | 63 | /** 64 | * Logs an Error message to the trace log. 65 | * 66 | * @param string $message Message to log. 67 | */ 68 | public static function error($message = '') { 69 | self::log('Error', $message); 70 | } 71 | 72 | /** 73 | * Logs a Fail message to the trace log. 74 | * 75 | * @param string $message Message to log. 76 | */ 77 | public static function fail($message = '') { 78 | self::log('Fail', $message); 79 | } 80 | 81 | /** 82 | * Logs a message to the trace log. 83 | * 84 | * @param string $category Category to log (Info, Warn, Error, Fail). 85 | * @param string $message Message to log. 86 | */ 87 | public static function log($category = 'Info', $message = '') { 88 | // Timing 89 | $timeFromFirst = 0; 90 | $timeFromLast = 0; 91 | if (self::$_timingFirst == 0) { 92 | self::$_timingFirst = microtime(true); 93 | self::$_timingLast = self::$_timingFirst; 94 | } else { 95 | $timeFromFirst = (microtime(true) - self::$_timingFirst) * 1000; 96 | $timeFromLast = (microtime(true) - self::$_timingLast) * 1000; 97 | } 98 | 99 | // Log 100 | self::$_messages[] = array($message, $category, number_format($timeFromFirst, 2) . ' ms', number_format($timeFromLast, 2) . ' ms'); 101 | 102 | // Timing 103 | self::$_timingLast = microtime(true); 104 | } 105 | } -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | A client side Glimpse into whats going on in your server 2 | 3 | Overview 4 | -------- 5 | At its core Glimpse allows you to debug your PHP application right in the browser. Glimpse allows you to "Glimpse" into what's going on in your web server. In other words what Firebug is to debugging your client side code, Glimpse is to debugging your server within the client. 6 | 7 | Fundamentally Glimpse is made up of 3 different parts, all of which are extensible and customizable for any platform: 8 | 9 | * Glimpse Server Module (the one you are browsing right now) 10 | * Glimpse Client Side Viewer 11 | * Glimpse Protocol 12 | 13 | 14 | Getting started 15 | --------------- 16 | Installing Glimpse in a PHP application is very straightforward. Glimpse is supported starting with PHP 5.2 or higher. 17 | 18 | * For PHP 5.2, copy the source folder of this repository to your server and add as early as possible in your PHP script. 19 | * For PHP 5.3, copy the glimpse.phar file from the build folder of this repository to your server and add as early as possible in your PHP script. 20 | 21 | From that moment, navigate to your web application and append the ?glimpseFile=Config query string to enable/disable Glimpse. Optionally, a client name can also be specified to distinguish remote requests. 22 | 23 | 24 | How it Works 25 | ------------ 26 | On the Server: 27 | 28 | 1. Server collects all server side information that will aid in debugging (i.e. PHP configuration, environment, session variables, trace data, etc) 29 | 2. It does this by running through a pipeline of server side data providers that can be dynamically controlled and added to under plugin architecture 30 | 3. Before the response is send, the server formats this data in accordance with the Glimpse Protocol and serializes it as JSON 31 | 4. Depending on whether it is a Ajax request or not, the server embeds the JSON in the HTTP Header or in the content of the page 32 | 33 | On the Client: 34 | 35 | 5. Depending on whether it is a Ajax request or not, the picks up the JSON data and to the data set by executing a pipeline of client side data providers that can be dynamically controlled and added to under plugin architecture 36 | 6. The client side module then dynamically renders a client side UI (similar to Firebug Lite) that lets you view this data 37 | 38 | Glimpse can be turned on or off by a series of different mechanistic, but at its core if the Glimpse cookie is present the server will provide the "debug" data - as a security measure, the request for debug data is "authenticated". Via the plugin model, this authentication check can have any logic that is required by the site to ensure that unauthorized users don't have access to sensitive debug data. 39 | 40 | 41 | Server Implementations 42 | ---------------------- 43 | Given the scope of the project and what it can do, the concept isn't restricted to any one platform. Hence, once mature, Glimpse Server Module will be available on all major web platforms. 44 | 45 | Platforms currently supported: 46 | 47 | * ASP.Net Web Forms 48 | * ASP.Net MVC 49 | * PHP (the one you are currently browsing) 50 | 51 | Platforms soon to be supported supported: 52 | 53 | * Ruby on Rails 54 | 55 | NOTE - If you would like help develop a Glimpse Server Module for a given platform please let us know. 56 | 57 | 58 | Client Implementations 59 | ---------------------- 60 | To start with the Glimpse Client Side Viewer is simply a light weight JavaScript "plugin" that understands the Glimpse Protocol and knows how to render the data. From a technology standpoint we currently use jQuery as the client side framework. 61 | 62 | Eventually, we would like to have actual browser plugins that provide richer functionality and experience, but the JavaScript version of the Glimpse Client Side Viewer is surprisingly well featured, intuitive and provides a high fidelity experience. We also hope to have a version for mobile ready soon which customizes the viewing/usage experience when using a mobile device. 63 | 64 |  65 | 66 | 67 | Protocol 68 | -------- 69 | Details on the Glimpse protocol can be found at http://getglimpse.com/Protocol. -------------------------------------------------------------------------------- /source/Glimpse/Handler/Config.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | class Glimpse_Handler_Config 8 | implements Glimpse_Handler_Interface 9 | { 10 | /** 11 | * Processes the handler pre-run. 12 | * 13 | * @param Glimpse $glimpse The current Glimpse instance. 14 | * @return string The rendered handler. 15 | */ 16 | public function processPreRun(Glimpse $glimpse) { 17 | if (!isset($_REQUEST['glimpseFile']) || $_REQUEST['glimpseFile'] != 'Config') { 18 | return; 19 | } 20 | 21 | echo ""; 22 | echo ""; 23 | echo "What Firebug is for the client, Glimpse does for the server... in other words, a client side Glimpse into whats going on in your server.
| Turn Glimpse On | Turn Glimpse Off | Set Glimpse Session Name |
Drag the above button to your favorites bar for quick and easy access to Glimpse.
"; 34 | 35 | echo "This section tells you how Glimpse sees your requests.
This is the list of Glimpse plugins for this web application. Glimpse plugins show up as individual tabs in the Glimpse client. You can stop a plugin from being loaded by setting the plugins-disabled value in glimpse.ini.