<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Sat, 25 May 2013 04:51:36 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Kurt Payne's Blog: How to Unit Test pcntl_fork()]]></title>
      <guid>http://www.phpdeveloper.org/news/17421</guid>
      <link>http://www.phpdeveloper.org/news/17421</link>
      <description><![CDATA[<p>
<i>Kurt Payne</i> has a new post to his blog showing how you can <a href="http://kpayne.me/2012/01/17/how-to-unit-test-fork/">unit test your process forking</a> in your PHP application (<a href="http://php.net/pcntl">pcntl</a>).
</p>
<blockquote>
At some point, many php developers turn to the pcntl functions in php to write a daemon, or server, or simulate threading. But how do you unit test this with complete code coverage? [...] We need to engage some black arts php extensions to make this happen.  An installation guide follows, and the post ends with a complete listing of the unit test.
</blockquote>
<p>
He uses the <a href="https://github.com/sebastianbergmann/php-test-helpers">test_helpers</a> extension (as provided by <i>Sebastian Bergmann</i>) and <a href="https://github.com/zenovich/runkit/">Runkit</a> to allow the test to define new methods copying the current pcntl methods and mocks up the responses. Tests are included to check the parent of a process, checking the children of a process and testing that a fork could be made. Hes's even included <a href="http://kurtpayne.files.wordpress.com/2012/01/forktest_code_coverage.png?w=614&h=464">visual proof</a> of this working.
</p>]]></description>
      <pubDate>Thu, 19 Jan 2012 13:40:20 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Perplexed Labs Blog: PHP Forking to Concurrency with pcntl_fork()]]></title>
      <guid>http://www.phpdeveloper.org/news/14164</guid>
      <link>http://www.phpdeveloper.org/news/14164</link>
      <description><![CDATA[<p>
On the Perplexed Labs blog there's a recent post looking at how to <a href="http://blog.perplexedlabs.com/2010/03/02/php-forking-to-concurrency/">fork processes in PHP</a> with the help of the <a href="http://php.net/pcntl_fork">pcntl_fork</a> function and the process management extension.
</p>
<blockquote>
Let's say you want to take advantage of more than one core for a given process. Perhaps it performs many intensive computations and on a single core would take an hour to run. Since a PHP process is single threaded you won't optimally take advantage of the available multi-core resources you may have. Fortunately, via the Process Control (<a href="http://php.net/manual/en/book.pcntl.php">PCNTL</a>) extension, PHP provides a way to fork new child processes.
</blockquote>
<p>
He gives a quick snippet of code showing how to spawn off a few new processes, get their process IDs and watches a max number of children until one dies (then starts another).
</p>]]></description>
      <pubDate>Wed, 10 Mar 2010 13:05:59 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Ibuildings Blog: Boost performance with parallel processing]]></title>
      <guid>http://www.phpdeveloper.org/news/11798</guid>
      <link>http://www.phpdeveloper.org/news/11798</link>
      <description><![CDATA[<p>
On the Ibuildings blog today there's <a href="http://www.ibuildings.com/blog/archives/1539-Boost-performance-with-parallel-processing.html">a new post</a> from <i>Martin Roest</i> looking at parallel processing in PHP scripts and how it can help you with performance and simplifying your applications.
</p>
<blockquote>
The idea of parallel processing is when you take an atomic transaction or operation called a 'process' and run a couple of those at the same time. [...] In this example I had a PHP CLI script. The purpose of this script was to process remote documents and save it local. It fetched the document from a remote location, processed it and saved the result local - let's call this the transaction. Transactions were done sequentially. It took about 1 second for a transaction to complete and the script had to do roughly 3500 transactions.
</blockquote>
<p>
Obviously, this script/testing method was not very effective, so he went searching for an alternative. The best option came in the shape of forking processes - spawning off a separate script (via PHP's forking functionality) to do the work on one or multiple entries. It uses the <a href="http://php.net/pcntl_fork">pcntl_fork</a> and <a href="http://php.net/pcntl_waitpid">pcntl_waitpid</a> functions to spawn and manage these children. Once they're all finished - working in parallel - they return back to the main script to wait for the slower ones to catch up.
</p>]]></description>
      <pubDate>Fri, 23 Jan 2009 07:51:05 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Evert Pot's Blog: Forking and MySQL connections]]></title>
      <guid>http://www.phpdeveloper.org/news/11497</guid>
      <link>http://www.phpdeveloper.org/news/11497</link>
      <description><![CDATA[<p>
<i>Evert Pot</i> has a <a href="http://www.rooftopsolutions.nl/article/213">quick post</a> showing how you can make your code fork MySQL connections for better performance.
</p>
<blockquote>
For some of our long-running processes we use PHP. It makes total sense from our perspective, because we can re-use all our existing business logic from our main PHP web application. To make things more efficient, I recently started some work on using forks and have a couple of worker processes around.
</blockquote>
<p>
His sample script makes use of the <a href="http://php.net/pcntl_fork">pcntl_fork</a> and <a href="http://php.net/pcntl_wait">pcntl_wait</a> functions in PHP to spawn off processes that will be closed off when no longer needed.
</p>]]></description>
      <pubDate>Wed, 03 Dec 2008 12:07:32 -0600</pubDate>
    </item>
  </channel>
</rss>
