2

I run a php script through shell using the following:

php script.php

How do I type this command in order to run it on the background and also log the output to a file?

I've tried

php script.php 2>&1 > out.log

But once I close putty, the script stopped.

3 Answers 3

2

you can use nohup (no hang up)

  nohup php script.php 2>&1 > out.log

or you use cron or at to run your script in background

Sign up to request clarification or add additional context in comments.

1 Comment

The script is meant for cron but I would like to test it first by manually executing it before I setup the cron.
0

Add a & after the command.

2 Comments

It seems like even with the &, when I close my putty, the script still stopped. :(
Yeah you need use nohup as well (as in @donald123's answer). '&' at the end tells the shell "run in the background". Using "nohup" ensures the script ignores the "HUP" signal to quit when you log out.
0

Try call like this:

php script.php 2>&1 > out.log &

4 Comments

It seems like even with the &, when I close my putty, the script still stopped. :(
Maybe script is end and therefore was stopped.
Cant be i have 10,000 records on loop
Very weird. My script looks: <?php echo date('Y-m-d H:i:s').' START'; sleep(50); echo date('Y-m-d H:i:s').' END'; and call: php index.php 2>&1 > log & Next I close terminal and run again and list running script by command: ps afx |grep index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.