From 50f39bd732f07e2765c7b20e752db93c98038d86 Mon Sep 17 00:00:00 2001 From: Timo Kiefer Date: Sun, 13 Nov 2011 13:51:52 +0100 Subject: [PATCH 1/4] Fixed, the option includeLineNumbers if you rename the FirePHP Core class file name. --- lib/FirePHPCore/FirePHP.class.php | 9 ++++++--- lib/FirePHPCore/FirePHP.class.php4 | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/FirePHPCore/FirePHP.class.php b/lib/FirePHPCore/FirePHP.class.php index 65d83b5..4d7816f 100644 --- a/lib/FirePHPCore/FirePHP.class.php +++ b/lib/FirePHPCore/FirePHP.class.php @@ -3,6 +3,7 @@ // - cadorn, Christoph Dorn , Copyright 2007, New BSD License // - qbbr, Sokolov Innokenty , Copyright 2011, New BSD License // - cadorn, Christoph Dorn , Copyright 2011, MIT License +// - kmcs, Timo Kiefer , Coipyright 2011, MIT License /** * *** BEGIN LICENSE BLOCK ***** @@ -1002,9 +1003,11 @@ public function fb($object) if (isset($trace[$i]['class']) && isset($trace[$i]['file']) && ($trace[$i]['class'] == 'FirePHP' - || $trace[$i]['class'] == 'FB') + || $trace[$i]['class'] == 'FB' + || $trace[$i]['class'] == __CLASS__) && (substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php' - || substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php')) { + || substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php' + || $this->_standardizePath($trace[$i]['file']) == __FILE__)) { /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ } else if (isset($trace[$i]['class']) @@ -1825,4 +1828,4 @@ public function setRendererUrl($URL) { trigger_error('The FirePHP::setRendererUrl() method is no longer supported', E_USER_DEPRECATED); } -} \ No newline at end of file +} diff --git a/lib/FirePHPCore/FirePHP.class.php4 b/lib/FirePHPCore/FirePHP.class.php4 index d702cea..a43a91e 100644 --- a/lib/FirePHPCore/FirePHP.class.php4 +++ b/lib/FirePHPCore/FirePHP.class.php4 @@ -3,6 +3,7 @@ // - cadorn, Christoph Dorn , Copyright 2007, New BSD License // - qbbr, Michael Day , Copyright 2008, New BSD License // - cadorn, Christoph Dorn , Copyright 2011, MIT License +// - kmcs, Timo Kiefer , Coipyright 2011, MIT License /** * *** BEGIN LICENSE BLOCK ***** @@ -629,9 +630,11 @@ class FirePHP { if(isset($trace[$i]['class']) && isset($trace[$i]['file']) && ($trace[$i]['class']=='FirePHP' - || $trace[$i]['class']=='FB') + || $trace[$i]['class']=='FB' + || $trace[$i]['class']==__CLASS__) && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' - || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { + || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php' + || $this->_standardizePath($trace[$i]['file'])==__FILE__)) { /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ } else if(isset($trace[$i]['class']) From c60cfc7c89b80f1b57c72837194ad1f642185750 Mon Sep 17 00:00:00 2001 From: tk Date: Fri, 31 Aug 2012 12:44:40 +0200 Subject: [PATCH 2/4] New option, maxBytesToSent to prevent the nginx header buffer overflow, default is ~32k --- lib/FirePHPCore/FirePHP.class.php | 20 +++++++++++++++++++- lib/FirePHPCore/FirePHP.class.php4 | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/FirePHPCore/FirePHP.class.php b/lib/FirePHPCore/FirePHP.class.php index 4d7816f..8fcf823 100644 --- a/lib/FirePHPCore/FirePHP.class.php +++ b/lib/FirePHPCore/FirePHP.class.php @@ -3,7 +3,7 @@ // - cadorn, Christoph Dorn , Copyright 2007, New BSD License // - qbbr, Sokolov Innokenty , Copyright 2011, New BSD License // - cadorn, Christoph Dorn , Copyright 2011, MIT License -// - kmcs, Timo Kiefer , Coipyright 2011, MIT License +// - kmcs, Timo Kiefer , Copyright 2011, MIT License /** * *** BEGIN LICENSE BLOCK ***** @@ -238,6 +238,18 @@ class FirePHP { * @var object */ protected $logToInsightConsole = null; + + /** + * sent byes + * @var integer + */ + protected $sentBytes = 0; + + /** + * max sent bytes + * @var integer + */ + protected $maxBytesToSent = 32000; //~32k /** * When the object gets serialized only include specific object members. @@ -1059,6 +1071,10 @@ public function fb($object) $msg = '[' . $this->jsonEncode($msgMeta) . ',' . $this->jsonEncode($object, $skipFinalObjectEncode) . ']'; } + if($this->maxBytesToSent < ($this->sentBytes + strlen($msg))) { + return; + } + $parts = explode("\n", chunk_split($msg, 5000, "\n")); for ($i = 0; $i < count($parts); $i++) { @@ -1084,6 +1100,8 @@ public function fb($object) } } } + + $this->sentBytes += strlen($msg); $this->setHeader('X-Wf-1-Index', $this->messageIndex - 1); diff --git a/lib/FirePHPCore/FirePHP.class.php4 b/lib/FirePHPCore/FirePHP.class.php4 index a43a91e..6f25ccd 100644 --- a/lib/FirePHPCore/FirePHP.class.php4 +++ b/lib/FirePHPCore/FirePHP.class.php4 @@ -3,7 +3,7 @@ // - cadorn, Christoph Dorn , Copyright 2007, New BSD License // - qbbr, Michael Day , Copyright 2008, New BSD License // - cadorn, Christoph Dorn , Copyright 2011, MIT License -// - kmcs, Timo Kiefer , Coipyright 2011, MIT License +// - kmcs, Timo Kiefer , Copyright 2011, MIT License /** * *** BEGIN LICENSE BLOCK ***** @@ -171,6 +171,18 @@ class FirePHP { * @var boolean */ var $enabled = true; + + /** + * sent byes + * @var integer + */ + var $sentBytes = 0; + + /** + * max sent bytes + * @var integer + */ + var $maxBytesToSent = 32000; //~32k /** * The object constructor @@ -687,6 +699,10 @@ class FirePHP { $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']'; } + if($this->maxBytesToSent < ($this->sentBytes + strlen($msg))) { + return; + } + $parts = explode("\n",chunk_split($msg, 5000, "\n")); for( $i=0 ; $isentBytes += strlen($msg); $this->setHeader('X-Wf-1-Index',$this->messageIndex-1); From d1d84138aba881884406f8363abfb27aeea664e4 Mon Sep 17 00:00:00 2001 From: tk Date: Sun, 2 Sep 2012 17:23:33 +0200 Subject: [PATCH 3/4] add new option: (boolean) useGzipEncode. to enable gzip encoded firephp header data, the option is disabled by default. --- lib/FirePHPCore/FirePHP.class.php | 15 +++++++++++++-- lib/FirePHPCore/FirePHP.class.php4 | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/FirePHPCore/FirePHP.class.php b/lib/FirePHPCore/FirePHP.class.php index 8fcf823..993e23c 100644 --- a/lib/FirePHPCore/FirePHP.class.php +++ b/lib/FirePHPCore/FirePHP.class.php @@ -3,7 +3,7 @@ // - cadorn, Christoph Dorn , Copyright 2007, New BSD License // - qbbr, Sokolov Innokenty , Copyright 2011, New BSD License // - cadorn, Christoph Dorn , Copyright 2011, MIT License -// - kmcs, Timo Kiefer , Copyright 2011, MIT License +// - kmcs, Timo Kiefer , Copyright 2012, MIT License /** * *** BEGIN LICENSE BLOCK ***** @@ -206,7 +206,8 @@ class FirePHP { 'maxObjectDepth' => 5, 'maxArrayDepth' => 5, 'useNativeJsonEncode' => true, - 'includeLineNumbers' => true); + 'includeLineNumbers' => true, + 'useGzipEncode' => false); /** * Filters used to exclude object members when encoding @@ -724,6 +725,9 @@ public function detectClientExtension() // Check if FirePHP is installed on client via User-Agent header if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si', $this->getUserAgent(), $m) && version_compare($m[1][0], '0.0.6', '>=')) { + if(!version_compare($m[1][0], '0.8', '>=')) { + $this->setOption('useGzipEncode', false); + } return true; } else // Check if FirePHP is installed on client via X-FirePHP-Version header @@ -1044,6 +1048,9 @@ public function fb($object) } $this->setHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); + if($this->options['useGzipEncode'] && function_exists('gzencode')) { + $this->setHeader('X-Wf-Option-gzip', 'true'); + } $this->setHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/' . self::VERSION); $structureIndex = 1; @@ -1071,6 +1078,10 @@ public function fb($object) $msg = '[' . $this->jsonEncode($msgMeta) . ',' . $this->jsonEncode($object, $skipFinalObjectEncode) . ']'; } + if($this->options['useGzipEncode'] && function_exists('gzencode')) { + $msg = base64_encode(gzencode($msg)); + } + if($this->maxBytesToSent < ($this->sentBytes + strlen($msg))) { return; } diff --git a/lib/FirePHPCore/FirePHP.class.php4 b/lib/FirePHPCore/FirePHP.class.php4 index 6f25ccd..ccad020 100644 --- a/lib/FirePHPCore/FirePHP.class.php4 +++ b/lib/FirePHPCore/FirePHP.class.php4 @@ -3,7 +3,7 @@ // - cadorn, Christoph Dorn , Copyright 2007, New BSD License // - qbbr, Michael Day , Copyright 2008, New BSD License // - cadorn, Christoph Dorn , Copyright 2011, MIT License -// - kmcs, Timo Kiefer , Copyright 2011, MIT License +// - kmcs, Timo Kiefer , Copyright 2012, MIT License /** * *** BEGIN LICENSE BLOCK ***** @@ -149,7 +149,8 @@ class FirePHP { var $options = array('maxObjectDepth' => 5, 'maxArrayDepth' => 5, 'useNativeJsonEncode' => true, - 'includeLineNumbers' => true); + 'includeLineNumbers' => true, + 'useGzipEncode' => false); /** * Filters used to exclude object members when encoding @@ -499,6 +500,9 @@ class FirePHP { // Check if FirePHP is installed on client via User-Agent header if(@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si',$this->getUserAgent(),$m) && version_compare($m[1][0],'0.0.6','>=')) { + if(!version_compare($m[1][0], '0.8', '>=')) { + $this->setOption('useGzipEncode', false); + } return true; } else // Check if FirePHP is installed on client via X-FirePHP-Version header @@ -672,6 +676,9 @@ class FirePHP { } $this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); + if($this->options['useGzipEncode'] && function_exists('gzencode')) { + $this->setHeader('X-Wf-Option-gzip', 'true'); + } $this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.FirePHP_VERSION); $structure_index = 1; @@ -699,6 +706,10 @@ class FirePHP { $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']'; } + if($this->options['useGzipEncode'] && function_exists('gzencode')) { + $msg = base64_encode(gzencode($msg)); + } + if($this->maxBytesToSent < ($this->sentBytes + strlen($msg))) { return; } From 719e7dd27f219aefa17e11ef6c15e13eaae2721b Mon Sep 17 00:00:00 2001 From: tk Date: Sun, 2 Sep 2012 17:58:58 +0200 Subject: [PATCH 4/4] disable useGzipEncode if firephp version is not 0.7+ --- lib/FirePHPCore/FirePHP.class.php | 2 +- lib/FirePHPCore/FirePHP.class.php4 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/FirePHPCore/FirePHP.class.php b/lib/FirePHPCore/FirePHP.class.php index 993e23c..95dd788 100644 --- a/lib/FirePHPCore/FirePHP.class.php +++ b/lib/FirePHPCore/FirePHP.class.php @@ -725,7 +725,7 @@ public function detectClientExtension() // Check if FirePHP is installed on client via User-Agent header if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si', $this->getUserAgent(), $m) && version_compare($m[1][0], '0.0.6', '>=')) { - if(!version_compare($m[1][0], '0.8', '>=')) { + if(!version_compare($m[1][0], '0.7', '>=')) { $this->setOption('useGzipEncode', false); } return true; diff --git a/lib/FirePHPCore/FirePHP.class.php4 b/lib/FirePHPCore/FirePHP.class.php4 index ccad020..b24ffd7 100644 --- a/lib/FirePHPCore/FirePHP.class.php4 +++ b/lib/FirePHPCore/FirePHP.class.php4 @@ -500,7 +500,7 @@ class FirePHP { // Check if FirePHP is installed on client via User-Agent header if(@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si',$this->getUserAgent(),$m) && version_compare($m[1][0],'0.0.6','>=')) { - if(!version_compare($m[1][0], '0.8', '>=')) { + if(!version_compare($m[1][0], '0.7', '>=')) { $this->setOption('useGzipEncode', false); } return true;