BostonGuru
07-29-2006, 11:25 PM
I am currently working on a script which at one point executes a command. This command can take minutes to complete, which causes the entire page to take 3 minutes before it is displayed.
I have tried using:
exec("cmd");
$result = `cmd`;
passthru("cmd");
and have had the same results. Is there any PHP command which will start the command, but not wait for it to finish. The script does not need the results reported back, and users should be able to continue surfing the site while the command runs.
-Edward-
07-29-2006, 11:58 PM
Why not load it in an invisible iframe? and use ajax to project it to the location you want?
BostonGuru
07-30-2006, 12:11 AM
I suppose I could, but I would like to keep the site and script as clean as possible. If there is a way I can just have the process run in the background that would be ideal. I was thinking I could have the command be to have the command added to a textfile qeue, then create a crontab script which checks the textfile every minute for command lines and runs them if any are present.
BostonGuru
07-31-2006, 11:39 PM
Does anyone else have any suggestions before I try this?
Elliot A
07-31-2006, 11:59 PM
Put and ampersand after the command to make it run in the background.
$command = exec ( './some_script.sh &' );
BostonGuru
08-01-2006, 01:12 AM
Well I tried using the &, but it still hung. Luckily that reminded me that I could use the SCREEN command to open it up separately, and it would automatically close when its done. Thanks for the suggestion!
Elliot A
08-01-2006, 02:17 AM
Hmm, that should spin it off to a background process. Try pasting the command here
Mark S
08-01-2006, 02:32 AM
I am about to hit the sack (going to bed) but remember using shell_exec() at one point.. does that work for you?
BostonGuru
08-01-2006, 12:01 PM
Hmm, that should spin it off to a background process. Try pasting the command here
Which one?
shell_exec; I havn't heard of it, but it sounds similar to exec().
I think I am all set though because exec("SCREEN -d ./script.sh") works perfect.
Mark S
08-01-2006, 12:10 PM
Right.. but the screen session just sits there (on the server), right?
BostonGuru
08-01-2006, 12:35 PM
no the screen terminates once its finished