Page 1 of 1

Help with exec()

Posted: Sat Nov 08, 2008 3:13 pm
by paume
--------------------------------------------------------------------------------

Hi,

I want my php script (a.php) to call another script (b.php) and run it in background mode.

This is what I use in a.php:

exec ("/usr/bin/php b.php >/dev/null &");

And this is what I place in b.php (among other commands):

sleep(30)

When I run a.php, it calls b.php, which makes the script wait for 30 seconds.

Imagine that during those 30 seconds, the script a.php in the same http session calls the exec above for a second time.

It appears that the second call is ignored, as if the first "process" needs to be completed before b.php can be invoked again.

Is it possible to call b.php multiple times in multiple independent threads, so each of them can have a different outcome?

Thanks

Re: Help with exec()

Posted: Sat Nov 08, 2008 10:51 pm
by veridicus
You might want to look at pcntl_fork. But I think I remember once handling this issue by calling a regular shell script using exec() and starting the background process from that shell script.