Help with exec()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paume
Forum Newbie
Posts: 1
Joined: Sat Nov 08, 2008 3:10 pm

Help with exec()

Post 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
User avatar
veridicus
Forum Commoner
Posts: 86
Joined: Fri Feb 23, 2007 9:16 am

Re: Help with exec()

Post 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.
Post Reply