I want to run php file in background on fedora terminal in background.
Hello,
I want to run an php file on fedora terminal in background. When I am executing the file on terminal, it shows proper output. Whereas when I am trying to run the same file on terminal in background, there is no ouput in the file & the php file gets stopped. Please help us. I am using php with fedora 14. Regards, Gaurav. |
Can you give us more information on exactly how you are running it in the background and what the output is when you run it normally in a terminal?
|
php issue..
I am running the below command as root user on fedora machine.
php test.php > test.txt //works whereas when I am trying below command & it doesn't work. php test.php > test.txt & Gaurav, |
Are you seeing the file test.txt being created, or is not seeing it your issue? How are you triggering the execution of the PHP script? As a first guess, if you're not seeing the file I would guess it's being dropped into the home directory of whatever account is creating it; have you tried executing the same command but with an explicit declaration of where the file should be placed, like this?
php test.php > /tmp/test.txt & |
php issue..
Yes I can see the test.txt is created in the same directory. However when I am trying to run the same file in background on terminal & view the test.txt by using cat command, then I am facing below error:-
Error :- "[4]+ Stopped php test.php > test.txt" |
How exactly are you running the script? Are you firing it off as part of a window manager startup (such as the /etc/X11/gdm/PostLogin/Default script), as part of the user's shell startup (i.e. from a .bashrc file), as part of an init script (triggered by a runlevel change)... ?
|
php issue..
Hi,
I am running the file as a part of an init script. |
It looks like your init might be finishing execution before the called script does, forcing it to exit. Try modifying your init script to add the command "wait" immediately following the PHP script call, such as:
php test.php > test.txt & wait That will cause the process to wait until the test.php script finishes execution, after which the init script will continue. |
Or to allow the entire init script to run (if there's other things that need to finish), try this:
php test.php > test.txt & # # MORE COMMANDS # # MORE COMMANDS # # LAST COMMAND IN SCRIPT wait That way everything in the init script can continue while your PHP script runs in the background, but the init won't kill it off and will wait for it to finish execution before closing out. |
All times are GMT -5. The time now is 04:37 PM. |