1

I have a php script which is responsible for sending emails based on a queue contained in a database.

The script works when it is executed from my shell as such:

/usr/bin/php -f /folder/email.php

However, when I execute it to run in the background:

/usr/bin/php -f /folder/email.php > /dev/null &

It never completes, and the process just sits in the process queue:

clickonce: ps T

PID TT STAT TIME COMMAND

1246 s000 Ss 0:00.03 login -pf

1247 s000 S 0:00.03 -bash

1587 s000 T 0:00.05 /usr/bin/php -f /folder/email.php

1589 s000 R+ 0:00.00 ps T

So my question is how can I run this as a background process and have it actually execute? Do I need to configure my OS? Do I need to change the way I execute the command?

1 Answer 1

1

"T" in the "STAT" column indicates a stopped process. I would guess that your script is attempting to read input from stdin and is getting stopped because it is not the foreground process and thus is not allowed to read.

You should check if the script does indeed read something while executing.

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

7 Comments

Would a require_once statement or a db read be considered stdin in this case?
A read from the terminal is a read from stdin. As an experiment, see what happens if you try redirecting input from /dev/null
How would I form that statement? /usr/bin/php -f /folder/email.php < /dev/null & ?
That would work. As an alternative, carefully watch when you run the script in the background and see if the shell doesn't print a message about the php process getting stopped because of missing tty input.
It has worked for you, but you should still try to figure out why you are trying (unexpectedly) to read from stdin during execution. However, you now know what to look for. Good luck!
|

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.