<?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>My Beloved PHP &#187; Apache</title>
	<atom:link href="http://www.mybelovedphp.com/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mybelovedphp.com</link>
	<description>The Art of Quick &#38; Dirty Programming</description>
	<lastBuildDate>Sun, 06 Jun 2010 21:08:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dating takes time, women are difficult but PHP?</title>
		<link>http://www.mybelovedphp.com/2009/03/18/formatting-dates-in-different-languages/</link>
		<comments>http://www.mybelovedphp.com/2009/03/18/formatting-dates-in-different-languages/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 12:28:11 +0000</pubDate>
		<dc:creator>programmer</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mybelovedphp.com/?p=81</guid>
		<description><![CDATA[One of the big annoyances is having a blog or webpage in a certain language and that all the dates appear on your website in English. Of course you can choose just numbered formats, but sometimes the month or the day of the week in words adds that needed little extra polish. Formatting a date [...]]]></description>
			<content:encoded><![CDATA[<p>One of the big annoyances is having a blog or webpage in a certain language and that all the dates appear on your website in English. Of course you can choose just numbered formats, but sometimes the month  or the day of the week in words adds that needed little extra polish.</p>
<h5>Formatting a date in PHP</h5>
<p>Normally a date is formatted like this with the <strong>date() </strong>function:</p>
<pre class="brush: php;">
&lt; ?= date('d-m-Y') ?&gt;
</pre>
<h5>Formatting a localised date in PHP</h5>
<p>But to format a date in your preferred language you need to use the <strong>strftime</strong> function:</p>
<blockquote><p>Format the time and/or date according to locale settings. Month and weekday names and other language-dependent strings respect the current locale set with setlocale().</p></blockquote>
<p>So we also need the <strong>setlocale()</strong><strong> </strong>function. This function let you set the language to use for the formatting. Your system or server should have them installed, otherwise it&#8217;s not possible! And most of them are not installed by default, although easily available.<br />
What does the <strong>setlocale() </strong>function do:</p>
<blockquote><p>Returns the new current locale, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.<br />
An invalid category name also causes a warning message. Category/locale names can be found in <a href="http://www.faqs.org/rfcs/rfc1766">RFC 1766</a> and <a href="http://www.w3.org/WAI/ER/IG/ert/iso639.htm">ISO 639</a>. Different systems have different naming schemes for locales.</p></blockquote>
<p>Tough pages to consume to be honest, but let&#8217;s go on.</p>
<h5>Locales settings on your server</h5>
<p>You can find the installed localisations in this file on a Linux server:</p>
<pre class="brush: xml;">
vi var/lib/locales/supported.d/local
</pre>
<p>My server only had one line by default!<br />
Simply add the one&#8217;s you&#8217;re missing. You can find all possible localisations in this file:</p>
<pre class="brush: xml;">
/usr/share/i18n/SUPPORTED
</pre>
<p>Don&#8217;t add them all: it will decrease performance.</p>
<p>So we&#8217;re nearly done:</p>
<pre class="brush: php;">
&lt; ?
setlocale(LC_TIME,'nl-NL.UTF-8');
echo strftime('%s-$b-%y',time())
?&gt;
</pre>
<p>You need to enter the correct encoding aswell, otherwise it won&#8217;t work. This is dependent of the server settings, so it will influence the portability of your code a bit.<br />
Above code will give you the current date in Dutch, but we need another function to create localised dates from stored timestamps of the MySQL database.</p>
<h5>Converting stored Timestamps to PHP understandable format</h5>
<p>A MySQL timestamp value won&#8217;t work as a direct input to the strftime function. We need to convert it with another function: <strong>strtotime</strong>.</p>
<p>So we end up with something like this:</p>
<pre class="brush: php;">
&lt; ?
setlocale(LC_TIME,'nl-NL.UTF-8');
echo strftime('%A %d $b %y',strtotime($row-&gt;timestamp))
?&gt;
</pre>
<p><strong>Quite a long road to take for a boring date!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mybelovedphp.com/2009/03/18/formatting-dates-in-different-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another php bug?</title>
		<link>http://www.mybelovedphp.com/2008/04/12/another-php-bug/</link>
		<comments>http://www.mybelovedphp.com/2008/04/12/another-php-bug/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 22:30:52 +0000</pubDate>
		<dc:creator>programmer</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mybelovedphp.com/2008/04/12/another-php-bug/</guid>
		<description><![CDATA[Tonight I had trouble with parsing url&#8217;s. I wanted  to create some SEO-friendly url&#8217;s for a new site and the PATH_INFO server variable is a good base for it. My url: site/productname/camera It&#8217;s easy to parse the url to segments with an explode on &#8220;/&#8221; But I had a specific url that caused me troubles: [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight I had trouble with parsing url&#8217;s.</p>
<p>I wanted  to create some SEO-friendly url&#8217;s for a new site and the PATH_INFO server variable is a good base for it.</p>
<p>My url:</p>
<p><code>site/productname/camera</code></p>
<p>It&#8217;s easy to parse the url to segments with an explode on &#8220;/&#8221;</p>
<p>But I had a specific url that caused me troubles:</p>
<p><code>site/productname/cameraz.</code></p>
<p>Strangely  the  trailing dot disappeared:</p>
<p><code>echo $_SERVER['PATH_INFO']<br />
site/productname/cameraz</code></p>
<p>while</p>
<p><code>echo $_SERVER['REQUEST_URL']<br />
site/productname/cameraz.</code></p>
<p>That&#8217;s weird. I never saw those differences before.</p>
<p>I tried it on an old server with php 5.1.2. And NO difference there.</p>
<p>Somehow a bug entered in php 5.2.5 that deletes a trailing dot in $_SERVER['PATH_INFO'].</p>
<p>Be aware!</p>
<p>Of course it can also be caused in interaction with the apache-server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mybelovedphp.com/2008/04/12/another-php-bug/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to use Apache to compress (gzip) HTML, CSS and Javascript files</title>
		<link>http://www.mybelovedphp.com/2007/07/17/how-to-use-apache-to-compress-gzip-html-css-and-javascript-files/</link>
		<comments>http://www.mybelovedphp.com/2007/07/17/how-to-use-apache-to-compress-gzip-html-css-and-javascript-files/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 21:00:49 +0000</pubDate>
		<dc:creator>programmer</dc:creator>
				<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://www.mybelovedphp.com/archives/12</guid>
		<description><![CDATA[In an earlier post we showed you how to use PHP to compress html files and save valuable bandwidth. Now we will choose a setup where apache will compress the files. This is a more efficient setup for your serverconfiguration. Installing mod-deflate When Apache 2 is installed, mod_deflate is automatically installed, but not always enabled. [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.mybelovedphp.com/2006/11/29/how-to-use-gzip-compression-on-your-php-websites/">an earlier post</a> we showed you how to use PHP to compress html files and save valuable bandwidth. Now we will choose a setup where apache will compress the files. This is a more efficient setup for your serverconfiguration.</p>
<h5>Installing mod-deflate</h5>
<p>When Apache 2 is installed, mod_deflate is automatically installed, but not always enabled. To enable mod_deflate on a debian or ubuntu distribution, we can do:<br />
<code>a2enmod deflate</code><br />
On another system you have to edit  Apache2&#8242;s configuration file manually. First locate <em>mod_deflate.so</em> then edit the config file. Add this to the LoadModule section:<br />
<code>LoadModule deflate_module /PATH_TO/mod_deflate.so</code>Then restart Apache<br />
<code>apache2ctl restart</code></p>
<h5>Enable the SetOutputFilter DEFLATE filter</h5>
<p>Compression for APACHE 2 is implemented by the DEFLATE filter. To enable compression for documents simply put this filter in the appropriate Directory directives:</p>
<p><code><directory `/website`>SetOutputFilter DEFLATE</directory></code></p>
<h5>But we don&#8217;t want to compress picture-files</h5>
<p>But we do not want to compress everything! It doesn&#8217;t make any sense to compress files like gif, jpg or pdf&#8217;s. So we have to make an execption:</p>
<p><code>// Don't compress picture files<br />
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \ no-gzip dont-vary<br />
// Don't compress compressed files<br />
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary<br />
// Don't compress pdf's<br />
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary<br />
</code></p>
<h5>Conclusion</h5>
<p>Enabling compression is amazingly easy. Simply enable it in your apache directives. To sum it all up:<br />
<code><directory "/website"><br />
SetOutputFilter DEFLATE<br />
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \ no-gzip dont-vary<br />
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary<br />
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-var<br />
</directory><br />
</code></p>
<p>If you can&#8217;t edit your directives, you can alternatively use the .htaccess files in your webroot directory.<br />
That&#8217;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mybelovedphp.com/2007/07/17/how-to-use-apache-to-compress-gzip-html-css-and-javascript-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use gzip compression on your PHP websites</title>
		<link>http://www.mybelovedphp.com/2006/11/29/how-to-use-gzip-compression-on-your-php-websites/</link>
		<comments>http://www.mybelovedphp.com/2006/11/29/how-to-use-gzip-compression-on-your-php-websites/#comments</comments>
		<pubDate>Wed, 29 Nov 2006 15:37:53 +0000</pubDate>
		<dc:creator>programmer</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mybelovedphp.com/archives/8</guid>
		<description><![CDATA[Why? Compressing weboutput can save valuable bandwidth. The other advantage is that clients will load your websites faster. Gzip compression is supported by all modern browsers, so why not use it. It will compress your pages between 60% and 80%. So you will lower your bandwidth-costs by an average of 70%. Also your server can [...]]]></description>
			<content:encoded><![CDATA[<h5>Why?</h5>
<p>Compressing weboutput can save valuable bandwidth. The other advantage is that clients will load your websites faster. Gzip compression is supported by all modern browsers, so why not use it. It will compress your pages between 60% and 80%. So you will lower your bandwidth-costs by an average of 70%. Also your server can push more requests in case you have limited connection speed. Of course it will not work for images.</p>
<h5>Apache</h5>
<p>Your (Apache)server can do the job, but only when it is configured for it. There was a Apache 1 Module called mod_gzip that compresses the HTML as it sends it out. For Apache 2 this module is called <a href="http://httpd.apache.org/docs/2.2/mod/mod_deflate.html">mod_deflate</a> and it also compresses content before it is delivered to the client. </p>
<h5>PHP</h5>
<p>If you have no control over the Apache config files there is another way to solve the problem. Let PHP compress the content. If you have PHP > 4.3 you can use the zlib.output_compression.</p>
<p>It&#8217;s simple, change this setting to ON in your PHP ini file:<br />
<code>zlib.output_compression = On</code></p>
<p>That&#8217;s all. Every page will now send compressed content to every browser that understands the compression method. </p>
<blockquote><p><strong>NOTE: </strong>Don&#8217;t forget to disable gzip-compression in CMS-packages like Joomla in the administration section, otherwise you will spoil not only CPU resources but also you can run into trouble with the double compressed content that will show in some browsers only strange unreadable icons on the screen.</p></blockquote>
<p>You can also adjust the compression level by setting this between 1 and 9:<br />
<code>zlib.output_compression_level = 6</code></p>
<p>Make your own choice between CPU time to compress on a higher level and the less data that will be sent.</p>
<h5>Compression test</h5>
<p>I ran a test, without gzip the content of my page is <strong>20162 bytes</strong>. Now with different levels of compression, I came to the following results:</p>
<ol>
<li>6779 bytes</li>
<li>6690 bytes</li>
<li>6591 bytes</li>
<li>6264 bytes</li>
<li>6147 bytes</li>
<li>6134 bytes</li>
<li>6127 bytes</li>
<li>6127 bytes</li>
<li>6125 bytes</li>
</ol>
<p>I reduced the load of my webpage with 70%. The default value is 6, which is in my test the highest setting with some noticeable compression gains. So their is no real need for setting the level at all in the PHP ini:</p>
<pre><code>zlib.output_compression_level</code></pre>
<p>Just delete the line, if it&#8217;s there, PHP info will show -1 which is fine, because the default compression level is 6.</p>
<p>Measuring CPU load is nearly impossible and should not be considered to be an issue until you run into problems with that. In most cases bandwidth is limited and CPU time is plentiful.</p>
<h5>Alternative method 1</h5>
<p>There was another way of reaching the same by puting this at the start of every PHP-script:<br />
<code>< ? ob_start("ob_gzhandler"); ?></code></p>
<p>This still works in PHP 5, but according to the manual is not recommended. </p>
<blockquote><p>Note: You cannot use both ob_gzhandler() and zlib.output_compression. Also note that using zlib.output_compression is preferred over ob_gzhandler().</p></blockquote>
<h5>Alternative method 2</h5>
<p>If you have no access to your PHP.ini file you can set the option in the <a href="http://en.wikipedia.org/wiki/.htaccess">.htaccess file</a> in the root directory of your website. </p>
<pre><code>php_flag zlib.output_compression on</code></pre>
<h5>CSS</h5>
<p>When CSS is embedded it&#8217;s automatically compressed as well. For enabling CSS files to be compressed, simply rename your style.css files to style.php and it&#8217;s done automatically. Of course not forget to refer from your html to the new name when linking.</p>
<p>When you don&#8217;t want to adjust the HTML, or for use with WordPress or Joomla that work with different templates that are automatically referred to from the code, the following solution will work and it&#8217;s simple again:</p>
<ol>
<li>
Copy yourstylesheet.css to yourstylesheet.php
</li>
<li>
Replace the content of yourstylesheet.css to </p>
<pre><code>@import url(yourstylesheet.php);</code></pre>
</li>
</ol>
<p>Done!</p>
<p><strong>Edited 06-12-12</strong>:<br />
For Mozilla/Firefox you need to add </p>
<pre><code>< ? header("Content-type: text/css; charset: UTF-8"); ?></code></pre>
<p>to yourstylesheet.php at the start of the page. Otherwise the CSS is not recognised as CSS. In Opera/MSIE it was working correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mybelovedphp.com/2006/11/29/how-to-use-gzip-compression-on-your-php-websites/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
