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

PHPBuilder.com:
PHP Multithreading with cURL
Jun 10, 2011 @ 16:08:58

On PHPBuilder.com Jason Gilmore has posted a new tutorial about how to handle a more true version of multi-threading (non-native, of course) in a PHP application making HTTP requests. His method uses cURL, the popular extension that make working with socket connections a lot simpler.

This article explains an alternative solution that consists of sending multiple HTTP requests to the same Web server on which PHP is running. Each HTTP request triggers the execution of a different task. Many requests can be run at the same time without having to wait for each one to finish. [...] As you may know, PHP has no native support for multithreading like Java, but using the cURL extension makes multithreading possible in PHP.

He introduces cURL a bit, talking about the protocols it supports and how to check and see if you have the extension installed. He then walks through a sample connection, calling curl_setopt and curl_exec to fetch a remote page from a website. The real fun comes in when you use the curl_multi_add_handle and curl_multi_exec methods to run more than one request in parallel.

tagged: multithreading tutorial curl http request

Link:

Jack Slingerland's Blog:
24 PHP Dark Arts: Multi-Processing (Series)
Oct 01, 2010 @ 18:49:07

Jack Slingerland has a series of new posts to his blog looking at a method for multi-processing in PHP applications and some of the considerations of forking off processes from a main script.

Of all the glorious programming languages in existence, you've chosen to work with PHP. Okay, maybe you were forced to, but that doesn't mean you can't have fun right? Hmm, fun...What' fun? Threading, race conditions, and deadlocks. Sounds like loads of fun! But alas, PHP doesn't have functionality to cover this. True, but the host operating system does. We can just fork processes manually like in the good 'ole days' and then ride off into the sunset. But we shouldn't do that, it's wrong. It's taking advantage of PHP. Bah! We’re going to do it anyways. And FOR THE LOVE OF GOD, do not do this in production code. If you need multi-threading, use a different language.

Here's the three parts of the series:

If you'd like to download the source he's created during these three posts, you can grab it here.

tagged: multiprocessing tutorial multithreading

Link:

AlternateInterior.com:
Multi-Threading Strategies in PHP
May 02, 2007 @ 20:29:00

On AlternateInterior.com, there's the start of something that could be used to speed up the execution of your app - multi-threading in PHP.

PHP does not have threading anywhere in its massive core. We can, however, fake it by relying on the underlying operating system's multitasking abilities instead of PHP. This article will show you how.

PHP has no built in support for threading. But there can still be times when you've got lengthy code to run and idle CPU cycles you'd like to capitalize on. We can treat child processes as threads.

He (Brian Bosh) uses the example of executing five other PHP scripts inside of another through the use of a multi-threading class he's developed. Included is the code for both the class and the example code to use it.

tagged: multithreading strategy class background execute multithreading strategy class background execute

Link:

AlternateInterior.com:
Multi-Threading Strategies in PHP
May 02, 2007 @ 20:29:00

On AlternateInterior.com, there's the start of something that could be used to speed up the execution of your app - multi-threading in PHP.

PHP does not have threading anywhere in its massive core. We can, however, fake it by relying on the underlying operating system's multitasking abilities instead of PHP. This article will show you how.

PHP has no built in support for threading. But there can still be times when you've got lengthy code to run and idle CPU cycles you'd like to capitalize on. We can treat child processes as threads.

He (Brian Bosh) uses the example of executing five other PHP scripts inside of another through the use of a multi-threading class he's developed. Included is the code for both the class and the example code to use it.

tagged: multithreading strategy class background execute multithreading strategy class background execute

Link:


Trending Topics: