views:

103

answers:

5

Hello, does PHP support something like ampersand in bash (forking)? Let's say I wanted to use cURL on 2 web pages concurrently, so script doesn't have to wait before first cURL command finnishes, how could one achieve that in PHP? Something like this in bash:

 curl www.google.com &
 curl www.yahoo.com &
 wait
+1  A: 

Does PHP support something like ampersand in bash (forking)?
No. See the other answers, though I do point out that the PCNTL extension is UNIX only.

...how could one achieve that in PHP?*
cURL supports running multiple downloads concurrently.

Billy ONeal
+1  A: 

You can use popen or proc_open to open a process and let it run in the background, but there's no language support for background operations like there is for bash (which was made to run tasks, anyways; PHP was made for scripting stuff).

Using proc_open, you can then use proc_get_status to know when the processes are terminated. I'm afraid there's no wait equivalent.

zneak
A: 

You can write asynchronous methods if you really want to, but it's a lot of work, and probably a terrible design idea if you're using PHP.

Azeem.Butt
How can you write asynchronous methods with PHP?
zneak
http://netevil.org/blog/2005/may/guru-multiplexing
Azeem.Butt
A: 

Some kind of queuing mechanism is often preferable. Gearman is an open source queuing mechanism you can use. I also have a blog post on the Zend Server Job Queue that talks about running tasks asynchronously Do you queue? Introduction to the Zend Server Job Queue.

You could also use something like the Zend Framework Queuing classes to implement some of the asynchronous work. Zend_Queue

Kevin Schroeder