Reputation: 61
I am trying to run a php CLI script in the background and it just won't run - it has a status of Stopped SIGTOU (Trying to write output) - Here are the details
I created a basic script test.php
<?php echo 'Hello world'.PHP_EOL; ?>
Here are the results of various tests:-
php -f test.php
(Hello world gets displayed) php -f test.php >test.log 2>&1
(Hello world gets put into test.log) php -f test.php >test.log 2>&1 &
--- I get [1]+ Stopped(SIGTTOU) php -f test.php > test.log 2>&1
-- and the job just sits there doing nothing nothing gets logged however lsof shows the log file is openIt is something to do with PHP? A similar shell script gets executed no problems in the background.
Upvotes: 4
Views: 1804
Reputation: 322
If readline is enabled in your build of php, simply pass /dev/null as the input.
In your example above, it would be:
php -f test.php </dev/null >test.log 2>&1
Upvotes: 5
Reputation: 61
This is resolved now -- thanks to all who responded. The problem was that Apple provide PHP pre-built with the OS - the CLI version was built with readline included - http://www.php.net/manual/en/intro.readline.php ... this prevents any background running of scripts because readline automatically starts IO with the TTY ...
My problem was that I couldn't build my own version of PHP because of this -> http://forums.macrumors.com/showthread.php?t=1284479 - once I got that resolved my background script issue was gone :)
Upvotes: 1
Reputation: 1346
Well, a PHP script stops when its done execution, ie a simple echo "Hello World" is done execution as soon as it outputted the string, i would guess it have something to do with it ;-)
Upvotes: -2