I am trying to run a PHP script in background on my Linux server over SSH (Putty) but I'm not getting this to work.

The command I want to run in background is:

php buildscript/build_css.php as root@FIG-VMSAM:/var/www/wem#

I have tried this and get only this and not working, ( do not build my CSS for me )

root@FIG-VMSAM:/var/www/wem# php buildscript/build_css.php &
[1] 2274

[1]+  Stopped                 php buildscript/build_css.php

I has also try start the command by normal and after this put this on background by <Ctrl>+z but it does not work either.

As background in my PHP Script I use system() and call stylus http://learnboost.github.com/stylus/ and inotifywait if this is to help?

Does someone know why this doesn't work for me?

  • Does the script run fine when in foreground? Because I think it stops due to an error. – laurent Jan 3 '13 at 17:31
  • Yes this work very good in foreground while I run this normal but not in background. – FIG-GHD742 Jan 3 '13 at 17:32

Another quick answer is..assumming that the program really needs no user input:

 php buildscript/build_css.php </dev/null &

The reason it is stopping is that the program is opening stdin for some reason, eventhough it might not need any input.

  • Very Good, this work for me, I will be happy to not need to has 5 terminals open at same time. – FIG-GHD742 Jan 3 '13 at 18:07

Would it be possible to run the script in a separate screen?

sudo apt-get install screen

Then use screen -S screenname where screenname is a name you give the screen session.

Once in the screen, you can then enter your command, php buildscript/build_css.php

To leave the session, use ctrl+a+d.

To get back into the session, use screen -r screenname

Do not worry, when you leave the session, the command will stay running in the background.

  • I will test, that the commando will be runing after I close putty is not what I want, Hope I can in this case tun this off. – FIG-GHD742 Jan 3 '13 at 17:29
  • When you exit putty, the screen session will continue to run. – Kruug Jan 3 '13 at 17:30
  • Sorry Try this but by some way the screen do not work very well on my server. – FIG-GHD742 Jan 3 '13 at 17:34
  • When you are in the screen session, are you in the proper directory? – Kruug Jan 3 '13 at 17:44
  • Can I leave the screen by a comando? Or start a new screen with a comando then automatic left the new screen? – FIG-GHD742 Jan 3 '13 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.