<?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>Thoughts Electrique &#187; PHP</title>
	<atom:link href="http://www.sebastian.himberger.de/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sebastian.himberger.de/blog</link>
	<description>Sebastian Himbergers blog about technology and software development</description>
	<lastBuildDate>Thu, 08 Jul 2010 17:05:46 +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>Installing PHP / PECL ImageMagick extension on 1&amp;1 managed server</title>
		<link>http://www.sebastian.himberger.de/blog/2009/09/26/installing-php-pecl-imagemagick-extension-on-11-managed-server/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/09/26/installing-php-pecl-imagemagick-extension-on-11-managed-server/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 03:42:16 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[1und1]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PECL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=477</guid>
		<description><![CDATA[I once had to install a custom PHP extension on a 1&#38;1 managed server. In this case the company had already purchased a managed server which was running the corporate website. They wanted to install an extranet-like webapplication which needed the ImageMagick PHP extension. In the following post I will outlike how I compiled and [...]]]></description>
			<content:encoded><![CDATA[<p>I once had to install a custom PHP extension on a <a title="1&amp;1 website" href="http://www.oneandone.com" target="_blank">1&amp;1</a> managed server. In this case the company had already purchased a managed server which was running the corporate website. They wanted to install an extranet-like webapplication which needed the <a title="ImageMagick extension" href="http://us3.php.net/manual/en/book.imagick.php">ImageMagick PHP extension</a>. In the following post I will outlike how I compiled and installed this extension on the managed server without having administrative access.</p>
<p><span id="more-477"></span></p>
<h3>Preparation</h3>
<p>To make the approach more modular we will use an environment variable pointing to our htdocs directory. I will call this variable $HTDOCS.</p>
<pre class="terminal">export HTDOCS=/kunden/homepages/.../htdocs</pre>
<p>We can check if everything is correct by changing into the htdocs directory.</p>
<pre class="terminal">cd $HTDOCS</pre>
<p>We will now create two directories:</p>
<ul>
<li><em>$HTDOCS/linux-src</em>: To hold all the data we need to compile the extensionn</li>
<li><em>$HTDOCS/linux</em>: To hold all the compiled data</li>
</ul>
<p>This setup allows us to delete the linux-src directory after we finished compiling the extension and save some diskspace.</p>
<pre class="terminal">mkdir -p $HTDOCS/linux-src
mkdir -p $HTDOCS/linux</pre>
<p>Now we will download the required sourcecode into our working directory:</p>
<pre class="terminal">mkdir -p $HTDOCS/linux-src/download
cd $HTDOCS/linux-src/download
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz
wget ftp://ftp.remotesensing.org/pub/libtiff/tiff-3.8.2.tar.gz
wget http://us3.php.net/get/php-5.2.10.tar.gz/from/us.php.net/mirror</pre>
<p><strong>Note:</strong> The URLs to the latest versions may change over time. You will have to adjust them and also watch for changed file names in the following steps. Also be sure to use the PHP version currently active on your managed server.</p>
<h3>Extracting the sourcecode</h3>
<p>Now create a folder for the extracted sourcecode and extract the source archives:</p>
<pre class="terminal">mkdir -p $HTDOCS/linux-src/extracted/imagick
mkdir -p $HTDOCS/linux-src/extracted/php-imagick
mkdir -p $HTDOCS/linux-src/extracted/libtiff
mkdir -p $HTDOCS/linux-src/extracted/php5

cd $HTDOCS/linux-src/extracted/imagick &amp;&amp; tar xfz $HTDOCS/linux-src/download/ImageMagick.tar.gz
cd $HTDOCS/linux-src/extracted/php-imagick &amp;&amp; tar xfz $HTDOCS/linux-src/download/imagick-2.3.0.tgz
cd $HTDOCS/linux-src/extracted/libtiff &amp;&amp; tar xfz $HTDOCS/linux-src/download/tiff-3.8.2.tar.gz
cd $HTDOCS/linux-src/extracted/php5 &amp;&amp; tar xfz $HTDOCS/linux-src/download/php-5.2.10.tar.gz</pre>
<h3>Building delegate libraries</h3>
<p>ImageMagick uses different delegate libraries for certain formats. We have to build these first so they can be incorporated into our ImageMagick build. In this case we will only use libtiff to allow the usage of the TIFF image format.</p>
<h4>Building libtiff from source</h4>
<p>Building libtiff is pretty straightforward. Simply use the following commands inside the extracted source archive:</p>
<pre class="terminal">./configure --prefix=$HTDOCS/linux/
make
make install</pre>
<h3>Building ImageMagick from source</h3>
<p>Change into the extracted source directory and type in the following:</p>
<pre class="terminal">./configure --without-perl --prefix=$HTDOCS/linux \
  CPPFLAGS="-I$HTDOCS/linux/include" LDFLAGS="-L$HTDOCS/linux/lib/"
make
make install</pre>
<p>You can type the following command to test the compiled ImageMagick.</p>
<pre class="terminal">make check</pre>
<p>After ImageMagick is built we can now go on and create the PHP extension.</p>
<h3>Building the ImageMagick PHP extenstion</h3>
<p>To compile the extension we have to have a PHP development environment in place. To create one we&#8217;ll simply compile and install PHP (this sounds more scary than it is).</p>
<h4>Building PHP from source</h4>
<p>Change into the extracted PHP archive and type in the following:</p>
<pre class="terminal">./configure --prefix=$HTDOCS/linux
make
make test
make install</pre>
<p>The <em>make test</em> target will run the PHP test suite. You can expect some tests to fail but if the number of failing tests is overwhelming you should get suspicious.</p>
<h4>Building the ImageMagick PECL extension</h4>
<p>Change into the extracted source archive and type in the following:</p>
<pre class="terminal">phpize --clean
phpize
./configure --prefix=$HTDOCS/linux --with-php-config=/usr/bin/php-config5 --with-imagick=$HTDOCS/linux</pre>
<p>The configure script should go through. Unfortunately it seems that the prefix and paths will not be set correctly in the <em>Makefile</em>. We will have to adjust this and replace the /usr/local paths with the path to our $HTDOCS/linux</p>
<pre class="terminal">echo "$HTDOCS/linux" | sed -e 's/\//\\\//g' &gt; htdocs_pattern &amp;&amp; \
  export HTDOCS_PATTERN=`cat htdocs_pattern` &amp;&amp; rm htdocs_pattern
perl -pi -e "s/\/usr\/local/$HTDOCS_PATTERN/g" Makefile</pre>
<p><strong>Note</strong>: The above command looks a bit freaky and is a bit of a quick hack. What it basically does it is escaping the slashes (/) in the <em>$HTDOCS</em> path and writing this to a file. Then exporting the content of the file to an environment variable and deleting the file. After this PERL is used to replace all <em>/usr/local</em> paths in the <em>Makefile</em> to <em>$HTDOCS/linux</em></p>
<p>After that we are good to go and can build the extension:</p>
<pre class="terminal">./configure --prefix=$HTDOCS/linux
make
make install</pre>
<p>Now the extension should be build successfully and is placed in the directory <em>$HTDOCS/linux/somepath</em> (the <em>make install</em> will tell you the extact path) . The last thing we have to do is activating the extension.</p>
<h3>Activating the extension</h3>
<p>To activate the extension for a certain folder, create a file named php.ini (for example in the $HTDOCS directory) with the following content inside the folder:</p>
<pre class="file">extension_dir=$HTDOCS/linux/somepath
extension=imagick.so</pre>
<p>Also don&#8217;t forget to activate PHP 5 with using a <em>.htaccess</em> file:</p>
<pre class="file">AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php</pre>
<p>That&#8217;s all. If you have any questions feel free to comment. I hope this helps some of you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/09/26/installing-php-pecl-imagemagick-extension-on-11-managed-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Custom php.ini and URL rewriting in Plesk 9 with fastcgi</title>
		<link>http://www.sebastian.himberger.de/blog/2009/03/19/custom-phpini-and-url-rewriting-in-plesk-9-with-fastcgi/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/03/19/custom-phpini-and-url-rewriting-in-plesk-9-with-fastcgi/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 17:43:42 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=366</guid>
		<description><![CDATA[For a current hosting server I&#8217;m using the Plesk control panel 9.0.1 for Ubuntu 8.04. Since version 9 Plesk allows the usage of Postfix as an MTA and PHP via FastCGI. This is very nice and much more secure than the old model using mod_php.
The Problem
One problem with the current Plesk version (as with most [...]]]></description>
			<content:encoded><![CDATA[<p>For a current hosting server I&#8217;m using the <a title="Official Plesk website" href="http://www.parallels.com/de/products/plesk/" target="_blank">Plesk control panel 9.0.1</a> for Ubuntu 8.04. Since version 9 Plesk allows the usage of <a title="Postfix website" href="http://www.postfix.org/" target="_blank">Postfix</a> as an <a title="Mail Transfer Agent explain at Wikipedia" href="http://en.wikipedia.org/wiki/Mail_Transfer_Agent" target="_blank">MTA</a> and PHP via <a title="FastCGI website" href="http://www.fastcgi.com/" target="_blank">FastCGI</a>. This is very nice and much more secure than the old model using mod_php.</p>
<h3>The Problem</h3>
<p>One problem with the current Plesk version (as with most Plesk versions :/) is that it has some nasty bugs. For example mod_rewrite doesn&#8217;t work with the FastCGI configuration. The problem is that the generated virtual host configuration has a small but important problem. The generated host looks something like this:</p>
<pre class="file">&lt;VirtualHost 88.198.164.10:80&gt;
  ServerName   playground.himberger.de:80
  ServerAlias  www.playground.himberger.de

  &lt;IfModule mod_fcgid.c&gt;
    &lt;Files ~ (\.php)&gt;
      SetHandler fcgid-script
      FCGIWrapper /usr/bin/php5-cgi .php
<strong>      Options ExecCGI</strong>
      allow from all
    &lt;/Files&gt;
  &lt;/IfModule&gt;
&lt;/VirtualHost&gt;</pre>
<p>The issue with this configuration is the line &#8220;<strong>Options ExecCGI</strong>&#8220;. This line enables the execution of CGI scripts for this particular directory but overrides all the Options set earlier. These are in parts needed for mod_rewrite. To fix this the line should be &#8220;<strong>Options +ExecCGI</strong>&#8220;. Sadly changing the configuration doesn&#8217;t help because at the next opportunity Plesk will regenerate the config file and your change is gone.</p>
<p>Luckily there is a way around this&#8230;</p>
<p><span id="more-366"></span></p>
<h3>Enable mod_rewrite (the solution)</h3>
<p>Luckily Plesk allows you to append a custom configuration to the virtual host by creating a file <em>vhost.conf</em> in the <em>${yourvhost}/conf</em> directory. By putting the following config in your <em>vhost.conf</em> you can take back the overwritten Options (don&#8217;t forget to restart the Apache HTTPD).</p>
<pre class="file">&lt;Directory "/var/www/vhosts/${yourvhost}/httpdocs"&gt;
  &lt;Files ~ (\.php)&gt;
    Options All
  &lt;/Files&gt;
&lt;/Directory&gt;</pre>
<p>You have to be very specific (using the enclosing Directory directive) to cause the current setting to be overridden.</p>
<p>With this knowledge at hand we can do some other nice tricks.</p>
<h3>Using a custom php.ini with fastcgi</h3>
<p>Since we are now able to override the Plesk generated configuration we can also alter the fastcgi command and for example specify a custom php.ini:</p>
<pre class="file">&lt;Directory "/var/www/vhosts/${yourvhost}/httpdocs"&gt;
  &lt;Files ~ (\.php)&gt;
   <strong> FCGIWrapper "/usr/bin/php5-cgi -c /etc/phpconfigs/${yourvhost}"  .php</strong>
    Options All
  &lt;/Files&gt;
&lt;/Directory&gt;</pre>
<p>The <strong><strong>FCGIWrapper</strong></strong> command will use the directory specified with the <em>-c</em> parameter for it&#8217;s php configuration. Simply put your php.ini in this directory and it will automatically be picked up. This way you can easily use a per customer PHP configuration with fastcgi and Plesk.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/03/19/custom-phpini-and-url-rewriting-in-plesk-9-with-fastcgi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enterprise grade software is an euphemism</title>
		<link>http://www.sebastian.himberger.de/blog/2008/12/04/enterprise-grade-software-is-an-euphemism/</link>
		<comments>http://www.sebastian.himberger.de/blog/2008/12/04/enterprise-grade-software-is-an-euphemism/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 19:48:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Cal Henderson]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Enterprise]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=163</guid>
		<description><![CDATA[I recently had to restart a Java webapplication because somehow the JDBC connection to the database server was hanging completely. This reminded me of a sentence a friend of mine told me during the OpenCms Days 2008.
&#8220;Enterprise software just means that it&#8217;s targeted at customers who can afford the guy who restarts the application server [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to restart a Java webapplication because somehow the JDBC connection to the database server was hanging completely. This reminded me of a sentence a friend of mine told me during the OpenCms Days 2008.</p>
<blockquote><p><em>&#8220;Enterprise software just means that it&#8217;s targeted at customers who can afford the guy who restarts the application server every few hours.&#8221;</em></p></blockquote>
<p>I had to laugh because while the quote is clearly cynical it has a true core. Especially if you compare languages like Java and PHP it&#8217;s true that PHP doesn&#8217;t have these kind problems. This is mostly because of the <em>throw-away-the-state</em> nature of PHP. After every served request PHP forgets what it&#8217;s done before and has to completely rebuild the working environment at the next request. Java in contrast is able to remember things between requests. Which makes it more powerful but also harder to maintain (more state, more problems). I&#8217;m really not sure if I&#8217;m buying into this <em>enterprise-thing</em> anymore. Especially if you need scalability you definitely want to keep application state at a minimum and without state you don&#8217;t really need those big interconnected clusters of application servers any more.</p>
<p>Here is a nice talk about scalability and <em>serious</em> (speak enterprise) languages I found recently. It&#8217;s from Cal Henderson a software development guy at <a href="http://www.flickr.com/">Flickr</a>. It&#8217;s really worth watching. Even if you&#8217;re not into Python and Django.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/i6Fr65PFqfk&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/i6Fr65PFqfk&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>(Watch it at: <a href="http://www.youtube.com/watch?v=i6Fr65PFqfk&amp;feature=PlayList&amp;p=D415FAF806EC47A1&amp;index=10">http://www.youtube.com/watch?v=i6Fr65PFqfk&amp;feature=PlayList&amp;p=D415FAF806EC47A1&amp;index=10</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2008/12/04/enterprise-grade-software-is-an-euphemism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Runkit with PHP on Linux (Debian Etch)</title>
		<link>http://www.sebastian.himberger.de/blog/2008/11/23/runkit-with-php-on-linux-debian-etch/</link>
		<comments>http://www.sebastian.himberger.de/blog/2008/11/23/runkit-with-php-on-linux-debian-etch/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 20:26:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PECL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Runkit]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=19</guid>
		<description><![CDATA[The forbidden fruit
I recently discovered runkit for PHP and thought it could be a solution for a few problems I ran into during my work on various projects.
At heart runkit allows you do to stuff with PHP you shouldn&#8217;t, but eventually want to, do. In my case this is basically Sandboxing and redefining (even PHP-internal) [...]]]></description>
			<content:encoded><![CDATA[<h3>The forbidden fruit</h3>
<p>I recently discovered <a title="runkit PHP extension" href="http://de.php.net/runkit" target="_blank">runkit </a>for PHP and thought it could be a solution for a few problems I ran into during my work on various projects.</p>
<p>At heart runkit allows you do to stuff with PHP you shouldn&#8217;t, but eventually want to, do. In my case this is basically <a href="http://en.wikipedia.org/wiki/Sandbox_(computer_security)" target="_blank">Sandboxing</a> and redefining (even PHP-internal) functions. It really adds some cool stuff to your PHP toolbox. Have a look at the <a href="http://en.php.net/runkit" target="_blank">function reference</a> for the complete list.</p>
<p>Sadly enough the runkit PECL package does not work on Debian Etch (because Etch uses PHP 5.2.0+) so I had to build the package myself. Read on to find out how to build and install runkit on Debian etch and things to keep in mind when using runkit.</p>
<p><strong>Important:</strong> If you are unsure of using runkit have a look at The sections <em>The Caveat</em> and <em>Final Remarks</em> before you walk through the hassle of installing it.</p>
<p><span id="more-19"></span></p>
<h3>Install &amp; Configure runkit</h3>
<h4>Obtain the sources from the runkit CVS</h4>
<p>Obtaining the sources is pretty easy. Just open a terminal and enter the following commands (leave the password empty when prompted for it)</p>
<pre class="terminal">cvs -d:pserver:cvsread@cvs.php.net:/repository login
cvs -d:pserver:cvsread@cvs.php.net:/repository co pecl/runkit</pre>
<p>This will checkout the runkit codebase into your current working directory.</p>
<h4>Building the Debian package from the PECL source</h4>
<p>You need some tools for building the package so I installed them using aptitude.</p>
<pre class="terminal">sudo aptitude install dh-make-php php5-dev</pre>
<p>Then I created a kind of fake PECL package from the CVS sources to use it with the <a title="dh-make-pecl manual (I know.. it's Ubuntu)" href="http://manpages.ubuntu.com/manpages/intrepid/man1/dh-make-pecl.html" target="_blank">dh-make-pecl</a> tool. dh-make-pecl is a Debian tool which helps you building .deb from a PECL package. The PECL package is just a .tar.gz archive having the following structure:</p>
<div id="attachment_185" class="wp-caption alignnone" style="width: 193px"><a href="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/11/runkit-pecl-package.png"><img class="size-full wp-image-185" title="The runkit PECL package structure" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/11/runkit-pecl-package.png" alt="The runkit PECL package structure" width="183" height="361" /></a><p class="wp-caption-text">The runkit PECL package structure</p></div>
<p>I assembled this package by using simple mv and mkdir inside the CVS then I used tar to create the archive. I called it <em>runkit-cvs-&lt;date&gt;.tar.gz</em> but the name is basically irrelevant.</p>
<pre class="terminal">mkdir -p package/runkit-0.9
mv pecl/runkit/package*xml package/
mv pecl/runkit/* package/runkit-0.9/
cd package/; tar cfz ../runkit-cvs-`date +%Y%m%d%H%M`.tar.gz *; cd ..</pre>
<p>After I had the fake PECL package I could start creating the .deb from it. This was fairly simple.</p>
<pre class="terminal">dh-make-pecl --only 5 runkit-cvs*tar.gz
cd php-runkit-0.9
dpkg-buildpackage -rfakeroot</pre>
<p><em>dpkg-buildpackage</em> puts the created .deb parallel to the <em>php-runkit-0.9</em> directory. The <em>&#8211;only 5</em> parameter requests the dh-make-pecl command to only create a Debian source package for the PHP 5 module. Have a look at the manual for more information.</p>
<h4>Installing the package</h4>
<p>Installing runkit is now just a matter of typing <em>sudo aptitude install php5-runkit_0.9-1_i386.deb</em> and letting APT do it&#8217;s work. After that you have to create a configuration file under <em>/etc/php5/apache2/conf.d</em> called <em>runkit.ini</em> with the following contents:</p>
<pre class="file">extension=runkit.so

# comment out the following line to disable the overloading
# of PHP internal functions.
runkit.internal_override=1</pre>
<p>After that restart your Apache server and you are done with the installation. You can check if runkit was installed sucessfull by just creating a <em>phpinfo()</em> file and look if runkit is listed in the modules section.</p>
<div id="attachment_186" class="wp-caption alignnone" style="width: 510px"><a href="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/11/runkit-phpinfo.png"><img class="size-full wp-image-186" title="The runkit phpinfo() section" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/11/runkit-phpinfo.png" alt="The runkit phpinfo() section" width="500" height="124" /></a><p class="wp-caption-text">The runkit phpinfo() section</p></div>
<h3>The Caveat (Renaming PHP internal functions)</h3>
<p>I was quite happy to have all this stuff running but as we all know nothing is less predictable than solutions in information technology (apart from visiting relatives appearing out of nowhere). My first little project was to add some logging to the PHP built in <em>mail()</em> function. This may be useful to track down the spam sending contact form one of your customers build for his website on your server. I wrote a small script for testing purposes and just threw it in my public_html directory.</p>
<pre class="file">// Simple function to ouput a log message
function do_log($message) {
  echo 'LOG:'.$message;
}
// Wrapper for the PHP mail() function.
// Logs the mail parameters.
function logging_mail($to, $subject, $message, $headers = null, $params = null) {
  do_log('Sending mail to '.$to.' by '.__FILE__);
  php_mail($to, $subject, $message, $headers, $params);
}

// Interchange the built in function with my own
runkit_function_rename('mail','php_mail');
runkit_function_rename('logging_mail','mail');

mail('mymail@nodomain.xyz','Subject','message');</pre>
<p>It all seemed nice and logical but when I first opened my webbrowser and accessed the page I got a blank screen. My Apache error log revealed a <em>child pid 10051 exit signal Segmentation fault (11)</em> and commenting out the <em>mail()</em> and a quick page refresh even added a <em><strong>Fatal error</strong>:  Cannot redeclare do_log()</em> to the table. This looks really bad. It seems that renaming PHP internal functions and replacing them doesn&#8217;t work with runkit and the resulting crash of the PHP interpreter left the library of this interpreter in a corrupted state (user-defined functions where not removed because the script didn&#8217;t exit properly).</p>
<p>So as always: The part of a library you really need has a nasty bug. Although renaming user defined functions works great with runkit the part I really wanted doesn&#8217;t work out of the box.</p>
<p>I already have a solution in mind but this will be the topic of another blog post.</p>
<h3>Final remarks</h3>
<p>Runkit in theory is really great stuff. The problem with this library in realty is that it&#8217;s still beta (even after several years) and doesn&#8217;t seem to be actively maintained. Just a short look at the CVS repository and the bugtracker revealed that there hasn&#8217;t been much activety in the last year or so. This is a pitty because having the additional flexibilty that runkit provides really would be a killer feature for PHP developers. Other scripting languages (Python, Groovy and more) already bring these features to the table natively which allows you to write extremly elegant code.</p>
<p>If you are willing to dig into this extension prepare to do some work and be eventually disappointed because the solution you had in mind won&#8217;t work because of bugs. If you are willing to take this risk and invest some time and energy go for it. Maybe future versions of PHP will make runkit obsolete or a good-willing developer will take care of the bugs. Till then runkit remains black magic, it can make you incredibly powerful but also is a serious risk for your mental stability.</p>
<h3>More information</h3>
<ul>
<li><a title="An alternative way to build runkit" href="http://gabriel.e-radical.ro/blog1.php/2008/09/25/runkit" target="_blank">http://gabriel.e-radical.ro/blog1.php/2008/09/25/runkit</a> &#8211; An alternative way to build runkit</li>
<li><a title="Runkit function reference" href="http://en.php.net/runkit" target="_blank">http://en.php.net/runkit</a> &#8211; The runkit function reference</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2008/11/23/runkit-with-php-on-linux-debian-etch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
