Jump to content

fork


flyhoney

Recommended Posts

What is the best way to fork without using pcntl_fork()?

 

I've tried something to the effect of:

 

exec('script.php arg > /dev/null &');

 

But it seems to do weird stuff instead of what I actually want to do.

 

Is there another way I can run a script in the background, without having to wait for it to return for the parent script to continue?

Link to comment
https://forums.phpfreaks.com/topic/51529-fork/
Share on other sites

If you can't use pcnt_fork (which, to my knowledge is really just a wrapper for *nix style process forking) you're only other option is running exec('script.php arg > /dev/null &').  Out of curiosity why can't you use pcnt_fork? and what is the "weird stuff" that is happening when you try process forking via exec?

 

Patrick

Link to comment
https://forums.phpfreaks.com/topic/51529-fork/#findComment-253830
Share on other sites

I can't use pcntl_fork() because its not enabled or whatever on my webhost and I don't want to go through the trouble of installing php myself. 

 

The > /dev/null & approach seems to just fling the script calling exec() into this crazy loop that I have to kill.  It's rather strange.  The script calling exec() inserts a row into a database.  if I dont use > /dev/null, it inserts the row just fine, but the script has to wait for exec() to return.  If I add the > /dev/null &, it seems to never actually execute the script, and now, the database is blowing up uncontrollably.  I don't think I'm describing this well :(

Link to comment
https://forums.phpfreaks.com/topic/51529-fork/#findComment-253837
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.