flyhoney Posted May 15, 2007 Share Posted May 15, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/51529-fork/ Share on other sites More sharing options...
utexas_pjm Posted May 15, 2007 Share Posted May 15, 2007 Have a look at the pcntl_fork function. http://us2.php.net/pcntl_fork Quote Link to comment https://forums.phpfreaks.com/topic/51529-fork/#findComment-253767 Share on other sites More sharing options...
flyhoney Posted May 15, 2007 Author Share Posted May 15, 2007 Hey you, I go to UT also, but that actually doesn't help me at all. Quote Link to comment https://forums.phpfreaks.com/topic/51529-fork/#findComment-253772 Share on other sites More sharing options...
utexas_pjm Posted May 15, 2007 Share Posted May 15, 2007 lol -- what doesn't help you? UT? Or the function? (hook 'em) Patrick Quote Link to comment https://forums.phpfreaks.com/topic/51529-fork/#findComment-253793 Share on other sites More sharing options...
flyhoney Posted May 15, 2007 Author Share Posted May 15, 2007 Oh that was ambiguous, lolz. I can't use pcntl_fork(). But I need to start the script in the background somehow, because I can't wait for it to return, it will take too long. Quote Link to comment https://forums.phpfreaks.com/topic/51529-fork/#findComment-253813 Share on other sites More sharing options...
utexas_pjm Posted May 15, 2007 Share Posted May 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51529-fork/#findComment-253830 Share on other sites More sharing options...
flyhoney Posted May 15, 2007 Author Share Posted May 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51529-fork/#findComment-253837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.