<?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>Dominique Stender &#187; PHP</title>
	<atom:link href="http://www.st-webdevelopment.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.st-webdevelopment.com</link>
	<description>Good software is only the beginning...</description>
	<lastBuildDate>Wed, 14 Apr 2010 17:50:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Thoughts on HipHop for PHP</title>
		<link>http://www.st-webdevelopment.com/php/2010/02/thoughts-hiphop-php/</link>
		<comments>http://www.st-webdevelopment.com/php/2010/02/thoughts-hiphop-php/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 17:26:39 +0000</pubDate>
		<dc:creator>Dominique</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[accelerator]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[facebook]]></category>

		<guid isPermaLink="false">http://www.st-webdevelopment.com/?p=321</guid>
		<description><![CDATA[An overview of the PHP-to-C++ transformer HipHop for PHP that was recently announced by Facebook. I give an analysis of it's potential along with the requirements and possible limitations.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-327" title="HipHop_logo_white" src="http://www.st-webdevelopment.com/wp-content/uploads/2010/02/HipHop_logo_white.png" alt="" width="213" height="278" />It has been almost two weeks now since Facebook announced <a title="Announcement for the HipHop for PHP code transformer" href="http://developers.facebook.com/news.php?blog=1&amp;story=358" target="_blank" onclick="pageTracker._trackPageview('/outgoing/developers.facebook.com/news.php?blog=1_amp_story=358&amp;referer=');">HipHop for PHP</a>. The source code is still not available because apparently they've ran into some compilation issues, according to <a title="HipHop for PHP on GitHub" href="http://github.com/facebook/hiphop-php" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/facebook/hiphop-php?referer=');">their GitHub</a> status. So in essence, not much is known about HipHop for PHP but I want to try to give my thoughts based on the small amount of information we have and my experience with similar technologies.</p>
<blockquote><p>Please note that the bits and pieces of information come from various sources and things may or may not be exactly as we think they are.</p></blockquote>
<p>In order to understand what HipHop for PHP does it is important to understand how PHP itself gets executed. In this article I will give a rough overview of the PHP execution process and make a few educated guesses in what aspect HipHop for PHP differs from there.</p>
<p>Based on the little information available online I'll discuss how HipHop for PHP is suitable for large businesses and what might turn out to be obstacles that are yet to remove.</p>
<h4><span id="more-321"></span>The PHP execution process</h4>
<p>PHP code can not be executed directly, a property it shares with all other scripting languages such as Python, Ruby and JavaScript. What makes PHP executable is the Zend Engine, and it does so in a two stage process.</p>
<ol>
<li>The scripts are parsed and analyzed, checked for syntactical and semantical errors and if all goes well the application is transformed into byte code.</li>
<li>Since the byte code is still not executable on a CPU, it is interpreted further into machine code (that is CPU dependent) and then executed.</li>
</ol>
<p>For most PHP applications the first parsing stage takes most of the total time. The second execution stage is comparatively fast. So in order to speed up a PHP application, most code optimizers hook into the Zend Engine after the first stage has been completed and save the generated byte code into a cache. In a consecutive call to the webserver the cache will be fed back into the Zend Engine, thus skipping the entire first stage of the execution process.</p>
<p>There are quite a few products on the market that behave in such a way. Zend itself offers the <a title="Zend Optimizer" href="http://www.zend.com/en/products/guard/zend-optimizer" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.zend.com/en/products/guard/zend-optimizer?referer=');">Zend Optimizer</a> (now part of Zend Guard), there is <a title="eAccelerator PHP optimizer" href="http://eaccelerator.net/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/eaccelerator.net/?referer=');">eaccelerator</a> and <a title="APC, the Alternative PHP Cache" href="http://pecl.php.net/package/APC" target="_blank" onclick="pageTracker._trackPageview('/outgoing/pecl.php.net/package/APC?referer=');">APC</a>, which comes as a PECL package.</p>
<h4>The execution process with HipHop for PHP</h4>
<p>What sets HipHop for PHP apart from these three (and no doubt other) accelerators is that it does not act as a cache. Instead, HipHop for PHP will transform your PHP application into C++ code and compile that directly into a binary which is executable.</p>
<p>In that sense, HipHop for PHP is probably very similar to <a title="Roadsend PHP" href="http://www.roadsend.com/home/index.php?pageID=compiler" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.roadsend.com/home/index.php?pageID=compiler&amp;referer=');">Roadsend PHP</a> which also generates executable code from PHP, albeit not by transforming it into C++ first.</p>
<p>In essence, HipHop for PHP will get rid not only of the first stage of the usual execution stage, but also of a big part of the second stage, namely the interpretation of byte code into machine code. Generally I believe it is safe to assume that HipHop for PHP has the potential to run an application much faster than any of the previously mentioned accelerators, simply because there is less for to be done at runtime. Time will tell.</p>
<p>For detailed information on the internals of HipHop for PHP make sure you watch the <a title="Video of the HipHop for PHP announcement" href="http://www.ustream.tv/recorded/4409735" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.ustream.tv/recorded/4409735?referer=');">Facebook Technology Tasting</a> video on ustream.</p>
<h4>Possible limitations</h4>
<p><strong>The requirements</strong><br />
The <a title="HipHop for PHP requirements" href="http://wiki.github.com/facebook/hiphop-php/building-and-installing" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wiki.github.com/facebook/hiphop-php/building-and-installing?referer=');">requirements to run HipHop for PHP</a> are available online. Nothing out of the ordinary at first sight. The page claims that HipHop for PHP is tested on <a title="The CentOS Linux distribution" href="http://centos.org" target="_blank" onclick="pageTracker._trackPageview('/outgoing/centos.org?referer=');">CentOS </a>and <a title="the Fedora Linux distribution" href="http://fedoraproject.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/fedoraproject.org/?referer=');">Fedora</a>. Both are venerable distributions, no doubt. But both also come without vendor support which may or may not be a problem for your organization.</p>
<p>Granted, companies who's codebase can actually benefit from HipHop for PHP will no doubt have a team of excellent system administrators which maintain Linux in their sleep. But those companies might also be in the situation that their customers demand a Linux distribution with commercial support, such as SLES, RedHat etc.</p>
<p>So this is more an organizational issue rather than a technical. That being said it is not clear yet whether or not packages will be released by other Linux distribution vendors once HipHop for PHP is out. If at all, it probably won't happen soon.</p>
<p>Coming back to the requirements for HipHop for PHP, it requires customized packages of libcurl and libevent, which again may or may not be an issue for your environment. Here I see the same organizational issue, but also a possible technical issue - you might be in the situation that you need the original libcurl or libevent for some other software on the server. Only a practical test will tell.</p>
<p><strong>Unsupported language constructs</strong><br />
As with most PHP caches and compilers, a few PHP language constructs are not supported. Most commonly known is the eval() construct which is simply not available in C++. Personally I believe that eval() is a bad thing to begin with and you can get around it in almost every cases. Sadly many PHP frameworks such as <a title="TYPO3 content management system" href="http://www.typo3.org" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.typo3.org?referer=');">TYPO3</a>, many <a title="PEAR - the PHP extension and application repository" href="http://pear.php.net" target="_blank" onclick="pageTracker._trackPageview('/outgoing/pear.php.net?referer=');">PEAR</a> packages, <a title="Drupal content management system" href="http://drupal.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/drupal.org/?referer=');">Drupal</a> and <a title="The Joomla content management system" href="http://www.joomla.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.joomla.org/?referer=');">Joomla</a> make use of eval().</p>
<p>If you're intending to run one of these through HipHop for PHP you might need to wait for an update from the community, patch it yourself, or remove the code from the system if you don't need it. In any case this is a time consuming task.</p>
<p>Aside from eval() a few more language constructs may not be supported or may not benefit from the compilation in terms of performance, such as call_user_func_array() and other 'dynamic' constructs like dynamic variables, dynamic includes or built-in functions like function_exists(), class_exists(), get_declared_classes() etc.</p>
<p>HipHop for PHP is no different from other caches and compilers in these regards, so please don't make that affect your choice. Just be aware that things might not be as easy as you'd like them to be.</p>
<p><strong>No Apache?</strong><br />
This is speculative at this point but the <a title="Running HipHop [for PHP]" href="http://wiki.github.com/facebook/hiphop-php/running-hiphop" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wiki.github.com/facebook/hiphop-php/running-hiphop?referer=');">Running HipHop</a> page on GitHub seems to indicate that HipHop for PHP will not make use of the Apache webserver but instead come with its own webserver. My assumption is that this means we'll have to handle HipHop for PHP through Apache, much in the same way that we frequently do with Tomcat. This is not necessarily an issue.</p>
<h4>The potential of HipHop for PHP</h4>
<p>Despite the limitations I mentioned above, I believe HipHop for PHP has the potential to take PHP much further into the enterprise environment than many of the existing solutions. If it can deliver what it promises it is definitely something we will take a very close look at to give our eCommerce framework a serious performance boost.</p>
<p>Very high on my wishlist is to run the transformation process from PHP to C++ but skip the compilation. If that's possible I see the chance to make debugging compile errors much easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.st-webdevelopment.com/php/2010/02/thoughts-hiphop-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Another reason to upgrade to PHP 5.3</title>
		<link>http://www.st-webdevelopment.com/php/2009/12/upgrade-reason-php-53/</link>
		<comments>http://www.st-webdevelopment.com/php/2009/12/upgrade-reason-php-53/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 10:45:33 +0000</pubDate>
		<dc:creator>Dominique</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[object orientation]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[static property]]></category>

		<guid isPermaLink="false">http://www.st-webdevelopment.com/?p=282</guid>
		<description><![CDATA[Dominique Stender outlines why to upgrade to PHP 5.3 by showcasing an issue in the handling of static properties with PHP 5.2]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-287" title="php code" src="http://www.st-webdevelopment.de/wp-content/uploads/2009/12/static.jpg" alt="php code" width="190" height="400" />In case you haven't found any specific reason to switch to PHP 5.3, I have one: Static properties.</p>
<p>Consider the following scenario: You have a group of classes, each responsible for returning a specific statistic. All these classes implement the same API, as given by a common abstract class.</p>
<p>Now, some of these statistics are publicly accessible, others require a certain access control permission to be set.</p>
<p>The logical approach would be to implement a static property to the abstract class, denying access by default. Those classes that are indeed public will overwrite the static property with the correct setting and become accessible.</p>
<p>The property is static to gain speed: There is no need to instantiate the class, if the access control is not satisfied.</p>
<p>Stripped down to the bare essentials the whole set of classes to outline the issue looks like this:</p>
<pre name="code" class="php">abstract class StatisticBase {
    public static $acl = '0';
} // end: class StatisticBase

class PublicStatistic extends StatisticBase {
    public static $acl = '1';
} // end: class StatisticBase

class AdminStatistic extends StatisticBase {
    // default value for $acl is fine
} // end: class AdminStatistic</pre>
<p>AdminStatistic is an implemented class that is private, indicated by the $acl property being 0. PublicStatistic on the other hand is public, hence $acl is 1.</p>
<p>Now before instantiating a specific class we can check whether or not the access condition is satisfied:</p>
<pre name="code" class="php">if ($user-&gt;isAdmin == true || PublicStatistic::$acl == 1) {
    // retrieve admin statistic...
} // end: if</pre>
<p>But naturally this is cumbersome as soon as you have more than a handful of statistics - you don't want to add another condition to your if-statement whenever you add a statistic. So the logical solution is a loop:</p>
<pre name="code" class="php">$statistics = array(
    'PublicStatistic',
    'AdminStatistic'
);

foreach ($statistics as $statClassName) {

    if ($user-&gt;acl == 1 || $statClassName::$acl == 0) {
        // retrieve current statistic...
    } // end: if
} // end: foreach</pre>
<p>Here PHP 5.2 will fail with a fatal error.</p>
<p>You can't access static class properties by means of using a variable for the classname. PHP 5.3 can. There is no really elegant solution for this. (If you know one, post it in the comments!)</p>
<p>While I'm glad that PHP 5.3 has one more OOP feature covered, It leaves me with the feeling that we still have a long way to go until PHP fully supports object orientation.</p>
<p>Now, if Novel would please release a PHP 5.3 package for SLES 10 and SLES 11... thank you</p>
]]></content:encoded>
			<wfw:commentRss>http://www.st-webdevelopment.com/php/2009/12/upgrade-reason-php-53/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Optimize your Wordpress Blog Performance</title>
		<link>http://www.st-webdevelopment.com/php/2009/12/optimize-wordpress-blog-performance/</link>
		<comments>http://www.st-webdevelopment.com/php/2009/12/optimize-wordpress-blog-performance/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 13:36:02 +0000</pubDate>
		<dc:creator>Dominique</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CSS sprites]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.st-webdevelopment.com/?p=195</guid>
		<description><![CDATA[A handful of worthy tips how to improve your Wordpress blog performance while keeping W3C compliance. I talk about how to reduce both the required bandwidth as well as pushing down the number of requests to a minimum.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-196" title="snowflake" src="http://www.st-webdevelopment.com/wp-content/uploads/2009/12/snowflake.jpg" alt="snowflake" width="190" height="400" />The famous blogging software <a title="The Wordpress blogging software" href="http://wordpress.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/?referer=');">Wordpress </a>has always been my tool of choice when setting up a blog-like website. The usability of the backend and the number of available themes and plugins make it ideal if you want to see quick results.</p>
<p>However, when it comes to SEO and bandwidth optimization and standard compliance many of the plugins fall short and require some additional attention. The good news is that usually many plugins are available to scratch a single itch. Picking the right one often avoids many glitches.</p>
<h4>Social network plugins and social bookmarks</h4>
<p>I want to reach out to people with this blog. This includes enabling my honored readers to quickly share my articles with their community through the various social networks.</p>
<p><a title="The TweetMeMe Wordpress Plugin" href="http://wordpress.org/extend/plugins/tweetmeme/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/tweetmeme/?referer=');">TweetMeMe Button</a> and <a title="The Facebook Share Wordpress plugin" href="http://wordpress.org/extend/plugins/facebook-share-new/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/facebook-share-new/?referer=');">Facebook Share</a> are two plugins that put nifty buttons in your blog that include counters to boast about how many people shared your content. Both are really great and work perfectly, but I encountered some issues due to which I removed both from this website after a test period of a couple of days.</p>
<p>I had to remove the <a href="http://wordpress.org/extend/plugins/tweetmeme/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/tweetmeme/?referer=');">TweetMeMe Button</a> simply because it loads content from the tweetmeme.com server which is currently very slow, thus slowing down my website as well. There is nothing the author of this plugin can do about it I guess.</p>
<p><a title="The Facebook Share Wordpress plugin" href="http://wordpress.org/extend/plugins/facebook-share-new/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/facebook-share-new/?referer=');">Facebook Share</a> on the other hand was removed because it uses an id="" attribute for the button it displays, even if the button is on the page multiple times. Since this is violating W3C compliance this plugin had to go, too.</p>
<p>In addition to that, both plugins cause my layout to look a little bit messy and 'cheap', which I try to avoid. Again, that is nothing that can be fixed by the plugin authors since it is just my personal opinion. I really liked both plugins but these minor glitches made me move on to...</p>
<h4>Tweet This - CSS sprites</h4>
<p>I found another nice extension for social bookmarks called <a href="http://wordpress.org/extend/plugins/tweet-this/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/tweet-this/?referer=');">Tweet This</a>. The author <a title="Richard Thripp (author of the Tweet This Wordpress plugin) on Twitter" href="http://twitter.com/richardxthripp" target="_blank" onclick="pageTracker._trackPageview('/outgoing/twitter.com/richardxthripp?referer=');">Richard X. Thripp</a> did a really great job on this, offering bookmark icons for not one but many social networks. That covers my bases.</p>
<p>However I enhanced this plugin slightly in order to utilize CSS sprites for the social bookmark icons. My friend Chris recently talked about <a title="Chris about CSS sprites." href="http://www.swift-lizard.com/2009/11/20/nice-article-about-using-css-sprites/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.swift-lizard.com/2009/11/20/nice-article-about-using-css-sprites/?referer=');">CSS sprites</a> on <a title="SwiftLizard.com - Design &amp; Development" href="http://www.swift-lizard.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.swift-lizard.com/?referer=');">his blog SwiftLizard.com</a>. Here is the concept in a nutshell:</p>
<p>If you display ten icons on your website the traditional way the browser has to request ten files from the server - one for each icon. Since usually browsers do only a handful of requests at a time this slows down your website. With CSS sprites however, you can utilize CSS and one single graphic containing all icons to achieve the same effect with only one image being requested. This results in website response times that are much lower, thus enabling a smoother surfing experience.</p>
<h4>Further optimization of Social bookmarks [added]</h4>
<p>Since I posted this article I further enhanced <a title="Improved Social Bookmark handling in Wordpress" href="/general/2009/12/changed-social-bookmarks/" target="_self">the way I handle social bookmarks</a> in this blog, you might want to check that out.</p>
<h4>WP Super Cache</h4>
<p>The plugin <a title="The WP Super Cache Wordpress plugin" href="http://wordpress.org/extend/plugins/wp-super-cache/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/wp-super-cache/?referer=');">WP Super Cache</a> almost needs no introduction. Written by Donncha O. Caoimh it enables us to circumvent PHP completely and serve static content in many cases. Naturally, this is much faster. The plugin is a must for anyone taking performance seriously. WP Super Cache alone reduced the initial response of my blog (time-to-first-byte) by 80%.</p>
<h4>iPhone and mobile browsers</h4>
<p>As the owner of a technology related website I believe it is reasonable (and my access statistics seem to agree) to believe that some of my visitors will visit the website from a mobile device such as the iPhone or a Blackberry. While technically the layout I chose for this blog looks ok in my iPhone, there is a lot of clutter that I don't want to wait for on my mobile device.</p>
<p>Thankfully there is a plugin called <a title="The WPTouch Wordpress plugin" href="http://wordpress.org/extend/plugins/wptouch/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/wptouch/?referer=');">WPtouch </a>which displays the blog in a highly stripped down but yet good looking manner when viewed with a recognized mobile browser. Not only do mobile visitors get their content faster by removing clutter, the usability is also highly increased. Perfect.</p>
<h4>Combining JavaScript and CSS files</h4>
<p>Similar to what I said earlier about many images slowing down a website, the same is true for many JavaScript or CSS files. Regardless of the file type you should keep your number of requests as low as possible. With Wordpress and its many plugins that is next to impossible though, unless you want to rewrite every plugin you install.</p>
<p>But there is hope. What CSS sprites achieve for icons, the <a title="The head Cleaner Wordpress plugin" href="http://wordpress.org/extend/plugins/head-cleaner/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/head-cleaner/?referer=');">Head Cleaner</a> plugin does for JavaScript and CSS files. It can combine all JavaScript files into one and do the same for CSS. Further, JavaScript can be minimized and both file types can be compressed, reducing not the number of requests but the bandwidth as well.</p>
<h4>Image size</h4>
<p>This is a classic. Double check the images you have on your website for size - the size measured in bytes, not pixels. If you're not sure how to reduce images byte-wise, there are online services like the one on <a title="Online image optimizer on dynamicdrive.com" href="http://tools.dynamicdrive.com/imageoptimizer/ " target="_blank" onclick="pageTracker._trackPageview('/outgoing/tools.dynamicdrive.com/imageoptimizer/?referer=');">dynamic drive</a> which can guide you (and save you lots of manual trial-and-error time).</p>
<p>General rule of thumb is that a png will be smaller than a gif and images with only a few colors should never be stored in a jpg. For example the ScrumMaster badge you see on the upper right was initially a jpg of 25kB. My all means the png I use now looks identical and is only 13kB.</p>
<h4>Results</h4>
<p>Given all the measures above, I was able to save over 50% of bandwidth and 75% of requests on the frontpage of my blog. No matter how fast your broadband connection is, you feel the difference. Even better, the website is still W3C compliant.</p>
<p>When in doubt what else you can do, I can recommend registering for Google Webmaster Tools and install their Page Speed Firefox plugin. It will hook into the famous Firebug plugin and provide you with an additional tab that gives very useful hints how to improve your website speed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.st-webdevelopment.com/php/2009/12/optimize-wordpress-blog-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
