Rich06
Rich06

Reputation: 61

PHP script won't run in the background

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:-

It is something to do with PHP? A similar shell script gets executed no problems in the background.

Upvotes: 4

Views: 1804

Answers (3)

Matthew Crenshaw
Matthew Crenshaw

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

Rich06
Rich06

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

Rasmus Styrk
Rasmus Styrk

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

Related Questions