LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 01-18-2012, 12:44 AM   #1
gauravwcities
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
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.
 
Old 01-18-2012, 12:47 AM   #2
xylos
LQ Newbie
 
Registered: Oct 2011
Location: USA
Distribution: Backtrack 5, Ubuntu 11.10, Linux Mint 12, Cyanogen Mod 7, FreeBSD 9.0
Posts: 17

Rep: Reputation: Disabled
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?
 
Old 01-18-2012, 12:51 AM   #3
gauravwcities
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
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,
 
Old 01-18-2012, 12:53 AM   #4
xylos
LQ Newbie
 
Registered: Oct 2011
Location: USA
Distribution: Backtrack 5, Ubuntu 11.10, Linux Mint 12, Cyanogen Mod 7, FreeBSD 9.0
Posts: 17

Rep: Reputation: Disabled
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 &
 
Old 01-18-2012, 12:59 AM   #5
gauravwcities
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
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"
 
Old 01-18-2012, 01:05 AM   #6
xylos
LQ Newbie
 
Registered: Oct 2011
Location: USA
Distribution: Backtrack 5, Ubuntu 11.10, Linux Mint 12, Cyanogen Mod 7, FreeBSD 9.0
Posts: 17

Rep: Reputation: Disabled
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)... ?
 
Old 01-18-2012, 01:11 AM   #7
gauravwcities
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
php issue..

Hi,
I am running the file as a part of an init script.
 
Old 01-18-2012, 01:21 AM   #8
xylos
LQ Newbie
 
Registered: Oct 2011
Location: USA
Distribution: Backtrack 5, Ubuntu 11.10, Linux Mint 12, Cyanogen Mod 7, FreeBSD 9.0
Posts: 17

Rep: Reputation: Disabled
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.
 
Old 01-18-2012, 01:23 AM   #9
xylos
LQ Newbie
 
Registered: Oct 2011
Location: USA
Distribution: Backtrack 5, Ubuntu 11.10, Linux Mint 12, Cyanogen Mod 7, FreeBSD 9.0
Posts: 17

Rep: Reputation: Disabled
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
the background image are not displayed in a php file htamayo Linux - Newbie 1 04-27-2011 01:21 AM
[SOLVED] get rid of terminal background at run level three jncross Linux - Newbie 5 01-04-2011 07:55 PM
terminal background problem in Fedora LXDE shva Linux - Desktop 3 12-20-2010 11:48 PM
Help with Frostwire, run the terminal in background? annihilan Slackware 4 08-01-2008 01:14 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 01:27 AM


All times are GMT -5. The time now is 01:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration