Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

is there a way to launch a php script and let it run on the server until it finishes?

I use this

php5-cgi /var/www/script.php -q &

connecting via putty. When I close it (the session) the script stops! Why does it run dependent on the session?

share|improve this question

4 Answers 4

up vote 2 down vote accepted

Try nohup and disown:

nohup php5-cgi /var/www/script.php -q &
disown
share|improve this answer
    
The nohup is redundant when you use disown –  symcbean Nov 18 '12 at 17:11

If screen is available, use that. Just start up a screen, run your command in it, detach the screen, and go on your merry way.

share|improve this answer

That because your process is not decoupled from the hangup signal. Use the following instead.

nohup php5-cgi /var/www/script.php -q 

You could also use a terminal multiplexer like screen or tmux if you want to be able to get back to the script output...

share|improve this answer

Also bear in mind that PHP has a script timeout limit after which it will automatically terminate script execution. You can modify the max_execution_time setting in your /etc/php5/cli/php.ini (the default is 30 seconds).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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