<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Juozas devBlog &#187; headers</title>
	<atom:link href="http://dev.juokaz.com/tag/headers/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.juokaz.com</link>
	<description>Random ideas, scripts and facts</description>
	<lastBuildDate>Mon, 22 Mar 2010 10:48:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Debugging with FirePHP and Firebug</title>
		<link>http://dev.juokaz.com/php/debugging-with-firephp-and-firebug</link>
		<comments>http://dev.juokaz.com/php/debugging-with-firephp-and-firebug#comments</comments>
		<pubDate>Thu, 12 Mar 2009 15:09:43 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[execution time]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[firephp]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=355</guid>
		<description><![CDATA[One may debug his application with print(&#8221;) statements all other the place or alert(&#8221;) for JavaScript. Luckily some years ago Firebug extension for Firefox was introduced, which introduced (?) console. Console works absolutely the same as in Linux and can be used not only to execute commands, but receive information from various sources.
To start with, [...]]]></description>
			<content:encoded><![CDATA[<p>One may debug his application with print(&#8221;) statements all other the place or alert(&#8221;) for JavaScript. Luckily some years ago <a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a> extension for Firefox was introduced, which introduced (?) console. Console works absolutely the same as in Linux and can be used not only to execute commands, but receive information from various sources.</p>
<p>To start with, I just love <a href="https://addons.mozilla.org/en-US/firefox/addon/6149">FirePHP</a>. This extension extends Firebug itself and allows PHP to show messages in the console.</p>
<p><img class="size-full wp-image-356" style="float: right;" title="FirePHP" src="http://dev.juokaz.com/wp-content/uploads/2009/03/firephp.png" alt="FirePHP" width="402" height="127" />FirePHP use special headers to send required information, so browses without FirePHP doesn&#8217;t feel any difference, but others can easily extract information. It doesn&#8217;t mean that DB profiling information should be visible in production server, but it definitely helps in development stages. If you look at normal website&#8217;s headers you would see something like this:</p>
<pre>HTTP/1.x 200 OK
Date: Thu, 12 Mar 2009 14:29:29 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.1 ...
X-powered-by: PHP/5.2.6-2ubuntu4.1
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html</pre>
<p>where FirePHP modifies it to:</p>
<pre>HTTP/1.x 200 OK
Date: Thu, 12 Mar 2009 14:28:39 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.1 ...
X-powered-by: PHP/5.2.6-2ubuntu4.1
X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2
X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1
X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2
X-Wf-1-1-1-1: 56|[{"Type":"INFO","File":"","Line":""},"This is a debug!"]|
X-Wf-1-1-1-2: 58|[{"Type":"ERROR","File":"","Line":""},"This is an error!"]|
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html</pre>
<p><a href="http://www.firephp.org/">FirePHP</a> website has libraries for sending these headers, but since I was trying it when using Zend Framework, I chose Zend_Log_Writer_Firebug module. It works as writer interface for Zend_Log and since Zend_Log is (or should be) used for all logging in ZF, you can get very nice access to all information (execution time, queries, warnings, etc.) from browser. For example, to send something with Zend Framework, code would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Place this in your bootstrap</span>
<span style="color: #000088;">$writer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Log_Writer_Firebug<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$logger</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Log<span style="color: #009900;">&#40;</span><span style="color: #000088;">$writer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Use this in your model, view and controller files</span>
<span style="color: #000088;">$logger</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is a log message!'</span><span style="color: #339933;">,</span> Zend_Log<span style="color: #339933;">::</span><span style="color: #004000;">INFO</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Simple and clean (it won&#8217;t work if Zend_Controller_Front is not used, look at <a href="http://framework.zend.com/manual/en/zend.log.writers.html#zend.log.writers.firebug">manual</a>).</p>
<p>Logging to files still should be used for information which will be required for further analysis, eg. payment gateway errors, but such information as execution time works perfectly in FirePHP. Users doesn&#8217;t care how fast page was rendered, but developers sometimes needs this information and in my opinion, using FirePHP sounds most reasonable. Have you tried it?</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/debugging-with-firephp-and-firebug/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Correct headers for dynamically generated content</title>
		<link>http://dev.juokaz.com/php/correct-headers-for-dynamically-generated-content</link>
		<comments>http://dev.juokaz.com/php/correct-headers-for-dynamically-generated-content#comments</comments>
		<pubDate>Sun, 15 Feb 2009 19:00:39 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[load time]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[uahoo]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yslow]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=155</guid>
		<description><![CDATA[Static images have correct headers &#8211; Apache sends them by default. Different story is with all dynamic generating content &#8211; if you don&#8217;t send correct headers user&#8217;s browser will load it every time. It&#8217;s not always good, because generated thumbnails doesn&#8217;t change every time and should be cached in browser&#8217;s cache. If you want to [...]]]></description>
			<content:encoded><![CDATA[<p>Static images have correct headers &#8211; Apache sends them by default. Different story is with all dynamic generating content &#8211; if you don&#8217;t send correct headers user&#8217;s browser will load it every time. It&#8217;s not always good, because generated thumbnails doesn&#8217;t change every time and should be cached in browser&#8217;s cache. If you want to reduce server load and increase loading speed you definitely need to send correct headers.</p>
<p>Our task is to give browser enough information to identify content, which later can be used to decided if content has changed, and if not &#8211; say it to browser without sending content again. Bigger picture is explained <a href="http://thoughtpad.net/alan-dean/http-headers-status.jpg">here</a>, I really recommend analysing it a little bit &#8211; it gives better understanding how headers work and what they mean.</p>
<p>As you saw in <a href="http://thoughtpad.net/alan-dean/http-headers-status.jpg">headers map</a>, there are many possible headers to send, but we can focus on three of them:</p>
<ol>
<li>Etag. Unique identified for output data (maybe hash)</li>
<li>Last-Modified. Date of last data modification</li>
<li>Expires. When to expire content</li>
</ol>
<p>Constructing algorithm is pretty simple, it can be explained in pseudo-code:</p>
<pre>get request headers
   is content expired
      send content, new headers
   else is content different (Etag)
      send content, new headers
   else
      304 header, no content</pre>
<p>I&#8217;ve created <em>outputCacheHeaders(&#8230;)</em> function which (available <a href="http://dev.juokaz.com/examples/expires-etag/headers.phps">here</a>) outputs all required headers and returns true if you need to output content or false if not. All you need to do is pass modification time, live time and data (two last ones are not required). Live time says how long should cache be kept and data is used to generate Etag. Very simple!</p>
<p>After enabling correct headers sending, my websites started to feel much faster, because HTTP requests takes much less time. Also, <a href="http://developer.yahoo.com/performance/rules.html">Yahoo performance tips</a> are really worth reading, really. There are many great tips and I have been using many of them for a long time. These tricks are much much more significant than 0.1 s. faster PHP rendering time.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/correct-headers-for-dynamically-generated-content/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
