The Little Guy Posted November 20, 2008 Share Posted November 20, 2008 Is it possible to run a php script as a background process? I don't want to have the command line window open while my php script runs, since it is an endless loop. Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/ Share on other sites More sharing options...
Daniel0 Posted November 20, 2008 Share Posted November 20, 2008 degeberg ~ # cat >> test.php <?php while (1) { } ?> degeberg ~ # php test.php& [1] 1990 degeberg ~ # ps -A | grep php 1990 pts/0 00:00:00 php Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-694510 Share on other sites More sharing options...
tomfmason Posted November 21, 2008 Share Posted November 21, 2008 If you want to do it on windows you can do something like this using COM: <?php $dir = "C:\\path\\to\\"; $obj = new COM('WScript.Shell'); $obj->run("cmd /K CD $dir & php your_script.php", 0, false); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-695118 Share on other sites More sharing options...
DarkWater Posted November 21, 2008 Share Posted November 21, 2008 And actually, if you're on Linux, Daniel's example would still close with the terminal. You'd probably want to use nohup. Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-695136 Share on other sites More sharing options...
Daniel0 Posted November 21, 2008 Share Posted November 21, 2008 And actually, if you're on Linux, Daniel's example would still close with the terminal. You'd probably want to use nohup. No it won't. I forgot to terminate the process and I just logged in again and checked. ps still shows it as running. Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-695329 Share on other sites More sharing options...
Maq Posted November 21, 2008 Share Posted November 21, 2008 Can't you just call it like this? # php your_file.php & Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-695629 Share on other sites More sharing options...
Daniel0 Posted November 21, 2008 Share Posted November 21, 2008 Can't you just call it like this? # php your_file.php & http://www.phpfreaks.com/forums/index.php/topic,226411.msg1043998.html#msg1043998 Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-695631 Share on other sites More sharing options...
Maq Posted November 21, 2008 Share Posted November 21, 2008 I amaze myself sometimes. Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-695643 Share on other sites More sharing options...
The Little Guy Posted November 21, 2008 Author Share Posted November 21, 2008 I guess it would help to say that I am using Windows (Vista). Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-695698 Share on other sites More sharing options...
corbin Posted November 21, 2008 Share Posted November 21, 2008 http://www.phpfreaks.com/forums/index.php/topic,221784.msg1018723.html It appears Windows has over secured things.... I know when ever a process runs as a different user it doesn't show (like scheduled tasks for example), but that's only true under certain circumstances (for example runas makes it show). Quote Link to comment https://forums.phpfreaks.com/topic/133529-php-background-process/#findComment-695813 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.