PHP script will not work in the background

I am trying to run php CLI script in the background and it just won't work - it has Stopped SIGTOU status (trying to write output). Here are the details

  • Mac OS X Lion 10.7.2
  • PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep 8, 2011 19:34:00)

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, the world is being displayed)
  • php -f test.php >test.log 2>&1 (Hello world gets 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 task just sits there, not writing anything but lsof shows that the log file is open.

Is this somehow related to PHP? A similar shell script does not perform any problems in the background.

+4
source share
3 answers

If readline is included in your php assembly, just pass / dev / null as input.

In the above example, this would be:

 php -f test.php </dev/null >test.log 2>&1 
+6
source

This is allowed now - thanks to everyone who answered. The problem was that Apple provided PHP with a pre-built OS - the CLI version was built with readline turned on - http://www.php.net/manual/en/intro.readline.php ... this prevents any background scripts from running, because readline automatically starts IO with TTY ...

My problem was that I could not build my own version of PHP because of this -> http://forums.macrumors.com/showthread.php?t=1284479 - as soon as I get this solution my script question was not: )

+1
source

Well, a PHP script stops when its executed, i.e. a simple "Hello World" echo is executed as soon as it outputs a string, I would suggest that this has something to do with it; -)

-2
source

Source: https://habr.com/ru/post/1382043/


All Articles