<?xml version="1.0"?>
<rss version="2.0"><channel><title>Devplace</title><link>http://www.devplace.nl/blog</link><lastBuildDate>Sat, 26 Dec 09 10:54:52 +0100</lastBuildDate><generator>Habari 0.7-alpha http://habariproject.org/</generator><item><title>PHP-FPM will be integrated in PHP 5.3.3</title><link>http://www.devplace.nl/blog/php-fpm-will-be-integrated-in-php-5-3-3</link><description>According to &lt;a href="http://php-fpm.org/"&gt;php-fpm.org&lt;/a&gt;, php-fpm (FastCGI Process Manager for PHP) will be integrated in the &lt;a href="www.php.net"&gt;PHP&lt;/a&gt; core as of version 5.3.3. This is good news for everyone that is running PHP as a fast-cgi server.&#xD;
&#xD;
I have been running &lt;a href="http://php-fpm.org/"&gt;php-fpm&lt;/a&gt; for about 1.5 year now on my home server. It took me some time to figure out the right setup, so I decided to share my setup. I use the following components:&#xD;
&#xD;
&lt;ul&gt;&#xD;
  &lt;li&gt;&lt;a href="http://httpd.apache.org/"&gt;Apache&lt;/a&gt; 2.2, with &lt;a href="http://www.fastcgi.com/"&gt;mod_fastcgi&lt;/a&gt;&lt;/li&gt;&#xD;
  &lt;li&gt;&lt;a href="http://www.php.net"&gt;PHP&lt;/a&gt; 5.3.1 with &lt;a href="http://php-fpm.org/"&gt;php-fpm&lt;/a&gt;&lt;/li&gt;&#xD;
&lt;/ul&gt;&#xD;
&#xD;
&lt;h3&gt;1. Compiling PHP with PHP-FPM&lt;/h3&gt;&#xD;
&#xD;
&lt;h3&gt;2. Configuring PHP-FPM&lt;/h3&gt;&#xD;
&#xD;
&lt;h3&gt;3. Configuring apache to use PHP-FPM via FastCGI&lt;/h3&gt;&#xD;
&#xD;
&lt;pre class="brush: plain"&gt;&#xD;
&amp;lt;IfModule mod_fastcgi.c&amp;gt;&#xD;
        FastCgiConfig -minProcesses 2 -singleThreshold 100 -killInterval 300 -autoUpdate -idle-timeout 240 -pass-header Authorization -pass-header HTTP_AUTHORIZATION&#xD;
&#xD;
        # Directory MUST exists, but the file is virtual and MUST NOT exist&#xD;
        # This is very important, because it is not clearly mentioned in the documentation&#xD;
        FastCgiExternalServer /var/www/fast-cgi/php53 -host 127.0.0.1:9000 -idle-timeout 300&#xD;
&#xD;
        &amp;lt;Location /fcgi-base/&amp;gt;&#xD;
                SetHandler fastcgi-script&#xD;
                Options ExecCGI&#xD;
        &amp;lt;/Location&amp;gt;&#xD;
&#xD;
        ScriptAlias /fcgi-base/ /var/www/fast-cgi/&#xD;
&#xD;
        # Tell apache to handle PHP scripts via fast cgi&#xD;
        AddType    application/x-httpd-fastphp5 .php&#xD;
        Action     application/x-httpd-fastphp5 /fcgi-base/php53&#xD;
&amp;lt;/IfModule&amp;gt;&#xD;
&lt;/pre&gt;</description><pubDate>Sat, 16 Jan 10 19:49:56 +0100</pubDate><guid isPermaLink="false">tag:www.devplace.nl,2010:php-fpm-will-be-integrated-in-php-533/1263668173</guid></item><item><title>Contributing to the PHP manual - an introduction</title><link>http://www.devplace.nl/blog/contributing-to-the-php-manual</link><description>There are many ways to contribute to the &lt;a href="http://www.php.net"&gt;PHP&lt;/a&gt; programming language. You can contribute by writing code, reporting bugs, helping other users on the &lt;a href="http://news.php.net"&gt;mailing lists&lt;/a&gt;, writing documentation etc. This article is a guide to start documenting for PHP. I think that one of the reasons that PHP is so widely used is because of the quality and completeness of the &lt;a href="http://www.php.net/manual/"&gt;PHP manual&lt;/a&gt;. &#xD;
&#xD;
The documentation team can't keep up with the code that is being written for PHP, so a lot of functionality that is available in PHP (or its extensions) is still undocumented. This is especially true for functions and modules that were added to PHP in the last couple of years. I think that it is important to create proper documentation, because otherwise the new functionality will only be used by experienced PHP developers that are aware of the existence of the undocumented functionality.&#xD;
&#xD;
&lt;h3&gt;How to start?&lt;/h3&gt;&#xD;
&#xD;
To start writing documentation you should think about what PHP functions, classes or extensions that you want to write documentation for. I think one can have several motives to start writing documentation for PHP. This list might help you decide what you want to document about, but is by no means complete.&#xD;
&#xD;
&lt;ul&gt;&#xD;
  &lt;li&gt;&#xD;
     You've used an extension in PHP that you've gotten pretty familiar with, but the documentation of this extension is incomplete.&#xD;
  &lt;/li&gt;&#xD;
  &lt;li&gt;You've encountered one or more bugs in the current documentation that you want to correct.&#xD;
  &lt;/li&gt;&#xD;
  &lt;li&gt;&#xD;
    You want to contribute to PHP because you use PHP a lot, but you are not comfortable with programming in C. In this case the pages &lt;a href="http://doc.php.net/php/undoc_functions.php"&gt;undocumented functions in the PHP manual&lt;/a&gt; or &lt;a href="http://doc.php.net/php/missing_examples.php"&gt;missing examples in the PHP manual&lt;/a&gt; are a good place to start.&#xD;
  &lt;/li&gt;&#xD;
&lt;/ul&gt;&#xD;
&#xD;
After you've decided what you want to document, it's time to read the &lt;a href="http://wiki.php.net/doc/howto"&gt;PHP documentation howto&lt;/a&gt;. This howto is not a definitive guide to start writing documentation for PHP, but it should be sufficient to get you started. The documentation team has switched to SVN a few months ago so there might be some references to CVS in the howto. &#xD;
&#xD;
After you've read the basic principles of the PHP documentation process, you can introduce yourself on the &lt;a href="http://news.php.net/php.doc"&gt;phpdoc mailinglist&lt;/a&gt; and start submitting patches to this list. &#xD;
&#xD;
&lt;h3&gt;Karma&lt;/h3&gt;&#xD;
&#xD;
You need to earn some karma before you will receive direct write access to the phpdoc SVN Repository. To earn karma you can join the discussions on the phpdoc mailinglist and start submitting patches to the documentation on the list. After you've earned some karma you can apply for a &lt;a href="http://www.php.net/svn-php.php"&gt;SVN account&lt;/a&gt;.&#xD;
&#xD;
&lt;h3&gt;Translating the manual&lt;/h3&gt;&#xD;
&#xD;
The PHP manual is available in many different languages. If you're not a developer, you can still contribute to the PHP documentation by translating the manual into your own language. You can start by posting a message to the &lt;a href="http://news.php.net/php.doc"&gt;phpdoc mailinglist&lt;/a&gt; in which you introduce yourself. It is also possible to subscribe yourself to a language specific mailing list. All documentation related mailing lists start with "php.doc.", you can view the available lists at &lt;a href="http://news.php.net/"&gt;news.php.net&lt;/a&gt;. Additional information can be found in the PHP wiki item "&lt;a href="http://wiki.php.net/doc/howto/translations"&gt;Working with translations&lt;/a&gt;".&#xD;
&#xD;
&lt;h3&gt;What you should know about the PHP Manual&lt;/h3&gt;&#xD;
&#xD;
Note that this information can also be found in the PHP wiki and elsewhere on the net, but I thought it could be useful to summarize it here.&#xD;
&#xD;
&lt;ul&gt;&#xD;
  &lt;li&gt;The PHP manual is written in &lt;a href="http://www.docbook.org/whatis"&gt;docbook&lt;/a&gt; XML format with a few enhancements that are PHP manual specific.&lt;/li&gt;&#xD;
&#xD;
  &lt;li&gt;The PHP documentation source resides in the "phpdoc" SVN module from the &lt;a href="http://svn.php.net"&gt;PHP SVN Repository&lt;/a&gt;. &lt;/li&gt;&#xD;
&#xD;
  &lt;li&gt;&lt;a href="http://wiki.php.net/doc/phd"&gt;PhD&lt;/a&gt; is the PHP tool that converts the docbook xml files to the various output formats of the PHP manual (currently PHP, HTML, PDF, CHM and man pages can be generated). Information about using PhD on windows can be found in an excellent blog post called "&lt;a href="http://elizabethmariesmith.com/2009/02/setting-up-phd-on-windows/"&gt;Setting up PhD on Windows&lt;/a&gt;" by Elizabeth Marie Smith.&lt;/li&gt;&#xD;
&#xD;
  &lt;li&gt;The &lt;a href="http://www.php.net/manual/"&gt;PHP manual&lt;/a&gt; is generated on a weekly base. The version that's used by the documentation team is updated four times a day and can be found at &lt;a href="http://docs.php.net/"&gt;http://docs.php.net/&lt;/a&gt;.&lt;/li&gt;&#xD;
  &lt;li&gt;&#xD;
    If you happen to work for a hosting provider, you can help the PHP Community by &lt;a href="http://php.net/mirroring.php"&gt;mirroring the PHP Manual&lt;/a&gt; for your country.&#xD;
  &lt;/li&gt;&#xD;
&lt;/ul&gt;</description><pubDate>Sun, 08 Nov 09 16:26:06 +0100</pubDate><guid isPermaLink="false">tag:www.devplace.nl,2009:contributing-to-the-php-manual/1255553880</guid></item><item><title>Storing large values in MySQL fields with PHP</title><link>http://www.devplace.nl/blog/storing-large-values-in-mysql-fields-with-php</link><description>Today a colleague at work ran into a problem when trying to store file contents into a MySQL database table. We are using this solution for quite some time now and it has always worked pretty good for documents and files up to 15 MB. The main reason for us to put files in the database is that it is easier to migrate a website to another server because the database contains all the data that we need. &#xD;
&#xD;
The problem appeared at a customers' webserver that is running Fedora. First we thought there must be something wrong with our PHP code. But as the code worked fine on our servers (Debian) we soon found out that we couldn't store more than 1 MB in our content field in the database. After a little more investigation the only solution to the problem seems to be raising the mysql system variable &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_allowed_packet"&gt;max_allowed_packet&lt;/a&gt; to a value that is bigger than the largest content that should go into a single field. &#xD;
&#xD;
For Debian the default max_allowed_packet size is 16 MB, but since the max_allowed_packet is not set for Fedora, MySQL defaults to 1 MB. We have no access to the MySQL server configuration so we had to solve problem this on the client side (our PHP code). An example of how this can be done is given here.&#xD;
&#xD;
&lt;pre class="brush: php"&gt;&#xD;
$fileName = '/file/name/of/uploaded/file.bin';&#xD;
$fileSize = filesize($fileName);&#xD;
&#xD;
// $db holds the (ADODB) database connection&#xD;
// Fetch current packet size&#xD;
$packetSize = (int) $db-&gt;GetOne('SELECT @@max_allowed_packet');&#xD;
if ($packetSize &amp;lt; $fileSize + 2048) {&#xD;
	$sql = sprintf('SET @@max_allowed_packet=%d', $fileSize + 2048);&#xD;
	$db-&gt;Execute($sql);&#xD;
}&#xD;
&#xD;
$db-&gt;Execute('INSERT INTO `file`(`filename`, `filesize`) VALUES(?, ?)', array($fileName, $fileSize));&#xD;
$fileId = $db-&gt;Insert_ID();&#xD;
&#xD;
// Here you can store the file contents in database&#xD;
$handle = fopen($fileName, 'r');&#xD;
while (($data = fread($handle, 524288)) &amp;&amp; strlen($data) &gt; 0) {&#xD;
	// Update record with chunks of 512K, until the file is completely in the database&#xD;
	// This prevents PHP from running out of memory&#xD;
	$sql = sprintf(&#xD;
		'UPDATE `file` &#xD;
		SET `contents` = CONCAT(`contents`, ?) &#xD;
		WHERE `id` = ?');&#xD;
	$this-&gt;db-&gt;Execute($sql, array($db-&gt;Quote($data), $fileId));&#xD;
}&#xD;
fclose($handle);&#xD;
&#xD;
// now set the  max_allowed_packet back to old value&#xD;
$sql = sprintf('SET @@max_allowed_packet=%d', $packetSize);&#xD;
$db-&gt;Execute($sql);&#xD;
&lt;/pre&gt;&#xD;
&#xD;
It is possible to store values up to 1 GB in a field in MySQL (as &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_allowed_packet"&gt;1 GB is currently the maximum allowed packet size&lt;/a&gt;). It is however not advisable to use the above method using &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat"&gt;CONCAT&lt;/a&gt; to put large files in the database, &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat"&gt;CONCAT&lt;/a&gt; gets very slow when the size of the blob gets bigger. If you want to put large files in the database you probably want to take a look at the &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_load-file"&gt;LOAD_FILE&lt;/a&gt; function. This is however more complex if MySQL doesn't run on the same server as your PHP code is running on.&#xD;
&#xD;
As you can see in the above PHP code the following MySQL queries can be used to retrieve and set the max_allowed_packet variable for the current connection.&#xD;
&#xD;
&lt;pre class="brush: sql"&gt;&#xD;
-- Fetch maximum allowed packet size (in bytes)&#xD;
SELECT @@max_allowed_packet;&#xD;
&#xD;
-- Set maximum allowed packet size (in bytes)&#xD;
SET @@max_allowed_packet=33554432;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
We use the following table definition to store the files (I have left out some unimportant fields). &#xD;
&#xD;
&lt;pre class="brush: sql"&gt;&#xD;
CREATE TABLE `file` (&#xD;
  `id` int(10) unsigned NOT NULL auto_increment,&#xD;
  `filename` varchar(255) NOT NULL,&#xD;
  `filesize` varchar(50) NOT NULL,&#xD;
  `contents` longblob NOT NULL,&#xD;
  PRIMARY KEY  (`id`)&#xD;
) ENGINE=InnoDB CHARSET=utf8&#xD;
&lt;/pre&gt;</description><pubDate>Tue, 29 Sep 09 22:55:00 +0200</pubDate><guid isPermaLink="false">tag:www.devplace.nl,2009:storing-large-values-in-mysql-fields-with-php/1254255396</guid></item><item><title>Running PHP as a fast-cgi server with apache and PHP-FPM</title><link>http://www.devplace.nl/blog/running-php-as-a-fast-cgi-server-with-apache-and-php-fpm</link><description>I have been running PHP (5) as a &lt;a href="http://ubuntuforums.org/showthread.php?t=341164" title="HOWTO: Apache+suExec+FastCgi+php4+php5 on Dapper"&gt;fast-cgi application via apache (with suexec)&lt;/a&gt; for quite some time. But it didn't feel right that the PHP application needed to be started over and over again (after 499 requests, because PHP dies after 500 requests). The startup of the php-cgi application causes some delay in the response from the apache server. This delay was visible for the visitors of my websites (it simply took about a second to start PHP and process the first page). &#xD;
&#xD;
Less people know that it is also possible to run PHP as a fast-cgi server that can be started apart from apache (or any other webserver that supports fast-cgi). This is possible with the vanilla PHP, but you will soon run into the 500 requests limit that's imposed by PHP. There's however a solution for this. By applying the &lt;a href="http://php-fpm.org"&gt;php-fpm&lt;/a&gt; patch to PHP the (fast cgi) process manager of PHP is extended with some really neat features.&#xD;
&#xD;
&lt;pre class="brush: plain"&gt;&#xD;
&amp;lt;IfModule mod_fastcgi.c&amp;gt;&#xD;
&#xD;
        # Directory MUST exists, but the file is virtual and MUST NOT exist&#xD;
        FastCgiExternalServer /var/www/fast-cgi/php53 -host 127.0.0.1:9000 -idle-timeout 300&#xD;
&#xD;
        &lt;Location /fcgi-base/&gt;&#xD;
                SetHandler fastcgi-script&#xD;
                Options ExecCGI&#xD;
        &lt;/Location&gt;&#xD;
&#xD;
        ScriptAlias /fcgi-base/ /var/www/fast-cgi/&#xD;
&#xD;
        AddType    application/x-httpd-fastphp5 .php&#xD;
        Action     application/x-httpd-fastphp5 /fcgi-base/php53&#xD;
 &#xD;
&amp;lt;/IfModule&amp;gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
</description><pubDate>Tue, 22 Sep 09 20:36:19 +0200</pubDate><guid isPermaLink="false">tag:habari.vandesande.no-ip.org,2009:using-php-fpm-with-apache/1250275054</guid></item></channel></rss>

