News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

VG Tech:
PHP Perform Requests in Parallel
July 23, 2013 @ 10:58:11

On the VG Tech blog today Espen Hovlandsdal has a quick tutorial showing you how to run cURL requests in parallel using the curl_multi_* functions included in PHP.

Ever had to request multiple HTTP-resources in your web application? Often, you need data from one request to be able to request the second - in this case there is little you can do but wait for the first to return. However, if the requests are not dependent on each other, you can use a pretty cool trick: curl_multi_*.

He first gives a single-threat example, showing how you might loop through a set of URLs to make the request and get the response. As an alternative, he shows the "multi" version right after. It sets up a "queue" of handles to different requests and executes them until they stop returning data. He also includes an example using the Guzzle HTTP client that makes it look cleaner and wraps some additional functionality around the requests.

0 comments voice your opinion now!
request parallel curl multiple tutorial guzzle

Link: http://tech.vg.no/2013/07/23/php-perform-requests-in-parallel

NetTuts.com:
Parallel Testing for PHPUnit with ParaTest
June 07, 2013 @ 11:44:48

On NetTuts.com today there's a new tutorial showing you how to use ParaTest for PHPUnit to execute your tests in parallel instead of the usual inline, in-order method.

PHPUnit has hinted at parallelism since 2007, but, in the meantime, our tests continue to run slowly. Time is money, right? ParaTest is a tool that sits on top of PHPUnit and allows you to run tests in parallel without the use of extensions. This is an ideal candidate for functional (i.e Selenium) tests and other long-running processes.

ParaTest operates as a separate binary that can easily be installed via Composer. They walk you through the install and show you what kind of options it lets you provide (like number of processes and the path to the PHPUnit executable). They show you how to write some parallel tests, five of them, each that sleeps for a certain amount of time. They also look at another tool that could help run your tests in parallel, Paraunit. They finish off the post with a look at some functional testing examples using Selenium, handling race conditions and some of the future plans for ParaTest's future.

0 comments voice your opinion now!
phpunit parallel testing paratest tutorial paraunit saucelabs

Link: http://net.tutsplus.com/tutorials/php/parallel-testing-for-phpunit-with-paratest

DZone.com:
Contributing to Paratest
March 06, 2013 @ 10:16:00

On DZone.com today there's an update about recent additions to Paratest, the parallel PHPUnit test runner (created by Brian Scaturro). He talks some about the benefits of running tests in parallel and shares some of the recent contributions to the project from other developers.

I've already written about my experiments with Paratest. Paratest is a PHPUnit wrapper that allows you to run tests written for PHPUnit in parallel, making us of multiple processes running on the same machine. In a world where cycle time is an important metric, trading resources to get the test suite to finish earlier is a net gain; especially when you're stepping on unstable stones and run the suite very often.

He (Giorgio Sironi) has contributed a new test runner to the project - the "WrapperRunner" that limits the number of processes spawned by the parallel testing tool. Another contribution came from Dimitris Baltas involving the addition of a TEST_TOKEN variable that can be used to uniquely identify each process as they're executing.

0 comments voice your opinion now!
contributions paratest parallel unittest phpunit runner multiprocess


DZone.com:
Parallel PHPUnit
February 05, 2013 @ 13:35:16

On DZone.com Giorgio Sironi has written up a new tutorial showing how to use parallelism with PHPUnit to execute multiple sets of tests at once, hoping for a performance gain.

Of course the cost of coordinating different processes is always going to be present, so we will never reach the theoretical speedup. I'll report later in this article some simulations. The most important constraints come from the design of our test suites. I can only think of two categories of tests as easily parallelizable: unit tests and Selenium tests.

He mentions one specific issue to watch out for - race conditions between the test sets (using the same backend resources). To help solve the issue, he recommends looking into Paratest, a tool that sits on top of PHPUnit and handles the execution of the tests in parallel. He creates some sample tests (they just compute values) and compares the runs of them in single- and multiple-process modes. The difference is a twenty-five percent drop in execution time for the parallel test runs.

0 comments voice your opinion now!
phpunit unittest parallel paratest project


David Müller's Blog:
Parallel processing in PHP
March 31, 2011 @ 13:41:37

In a recent post to his blog David Müller has taken a look at parallel processing in PHP using a few different methods - system calls, fork, and curl.

Since PHP does not offer native threads, we have to get creative to do parallel processing. I will introduce 3 fundamentally different concepts to emulate multithreading as good as possible.

For each of the technologies mentioned above, he provides a simple bit of sample code that does simple tasks like echoing out strings and writing to files. He also includes some benchmarks (take them with a grain of salt) of the three different methods showing how many iterations they could run through in ten seconds. He includes the benchmarking script if you'd like to try it out yourself.

0 comments voice your opinion now!
parallel processing tutorial system fork curl benchmark


Matthew Weier O'Phinney's Blog:
Running mod_php and FastCGI side-by-side
August 10, 2010 @ 14:06:44

On his blog today Matthew Weier O'Phinney talks about how to run mod_php and FastCGI side-by-side on a Zend Server instance.

I installed Zend Server some time ago, so I'm still on a PHP 5.2 mod_php binary. I have several PHP 5.3 binaries compiled and installed locally for running unit tests and sample scripts already -- so the question was how to keep my 5.2 mod_php running while simultaneously allowing the ability to run selected vhosts in 5.3? The answer can be summed up in one acronym: FastCGI.

He shows how to enable FastCGI in Apache (on Ubuntu), make a virtual host for your site and create a "cgi-bin" directory to contain the script(s) for your PHP versions as CGIs.

0 comments voice your opinion now!
modphp fastcgi parallel version


Sameer Borate's Blog:
Parallel cURL execution in PHP
August 05, 2010 @ 09:56:05

New on his blog today Sameer Borate has a post looking at his method for making parallel connections with curl based on this library from Pete Wardens.

Most people use the 'easy' mode - in this mode when we issue multiple requests, the second request will not start until the first one is complete. This is known as synchronous execution, and this is the one we normally use. [...] In [multi] mode all requests can be handled in parallel or asynchronously. And it can be quite handy and time saving on many occasions.

He gives some code examples of how to use the library to simplify the curl connections and requests and pass the result off to a callback when it's done. His more practical example shows how to search for a set of terms on Google and return the results for output.

1 comment voice your opinion now!
parallel curl execution tutorial library asynchronous


Kore Nordmann's Blog:
Native parallel PHP job queue
May 07, 2010 @ 14:40:29

Kore Nordmann has put together some scripts that will let you create a native parallel job queue using only PHP (and the PCTNL extension).

To make use of multiple cores for some rather long processing operations I needed a way to fork multiple workers from a single PHP script multiple times lately. So I created a small project on github which implements this in a way, so that it should reusable by anybody. This is far from being rocket science, but still might be useful to someone out there.

He uses the ShellJobProvider (extended from JobProvider) to handle the creation of the tasks. His simple example just spawns off a few echo statements and pushes the results to some files. You can get these libraries from hos github account. You'll need PHP 5.3 and the PCTNL extension installed to get it working.

0 comments voice your opinion now!
native parallel job queue pctnl


Ibuildings Blog:
Boost performance with parallel processing
January 23, 2009 @ 07:51:05

On the Ibuildings blog today there's a new post from Martin Roest looking at parallel processing in PHP scripts and how it can help you with performance and simplifying your applications.

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.

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 pcntl_fork and pcntl_waitpid 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.

0 comments voice your opinion now!
performance boost parallel processing ibuildings fork pcntlfork pcntlwaitpid


John Lim's Blog:
Parallel Processing in PHP
September 22, 2008 @ 08:47:14

John Lim has two new posts covering parallel processing in PHP and how to use this "divide and conquer" idea to not only speed up your code but to make it more maintainable down the road.

In the first post:

One problem we were having is that some of our batch processing jobs were taking too long to run. In order to speed the processing, we tried to split the processing file into half, and let a separate PHP process run each job. [...] Here is our technique for running multiple parallel jobs in PHP. In this example, we have two job files: j1.php and j2.php we want to run.

The code is included for the job files and the "controller" that manages them. In the second article, he builds on this and shows a more practical example - finding the median of a set of records out of a database.

0 comments voice your opinion now!
parallel processing tutorial divide conquer



Community Events





Don't see your event here?
Let us know!


code homestead introduction wordpress install library unittest release interview community series list threedevsandamaybe laravel api configure language application developer podcast

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework