Re: [PHP] PHP script won't run in the background

2011-11-30 Thread Alain Williams
On Wed, Nov 30, 2011 at 01:01:48PM +0100, richard gray wrote:

> >You need a bit more info, get a backtrace with 'where'.
> Thanks for the response Alain - below is the output:-

Ah, much more useful .

> [rich@LeMans] (/Web/scripts)> gdb --pid=3294
> GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug  8 20:32:45 
> UTC 2011)
> Copyright 2004 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain 
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for details.
> This GDB was configured as "x86_64-apple-darwin".
> /Web/scripts/3294: No such file or directory
> Attaching to process 3294.
> Reading symbols for shared libraries . done
> Reading symbols for shared libraries 
> 
>  
> done
> Reading symbols for shared libraries + done
> 0x7fff8f8ac7ee in __ioctl ()
> (gdb) where
> #0  0x7fff8f8ac7ee in __ioctl ()
> #1  0x7fff8f8ac1fe in ioctl ()
> #2  0x7fff910a6b1c in tcsetattr ()

OK - it is setting tty modes as I suspected.

> #3  0x00010ab05df7 in tty_end ()
> #4  0x00010ab05c39 in tty_init ()
> #5  0x00010aaf7261 in el_init ()
> #6  0x00010aafeb8e in rl_initialize ()
> #7  0x00010a3ef39a in zm_startup_readline ()

This is the readline routine ... probably setting the tty to raw mode, thus the 
tcsetattr() above.

Look at the link below, it is how your CLI version of PHP is compiled:

http://www.php.net/manual/en/readline.installation.php

readline is mentioned as part of CLI:

http://www.php.net/manual/en/features.commandline.usage.php

> #8  0x00010a37a1c8 in zend_startup_module_ex ()
> #9  0x00010a38166b in zend_hash_apply ()
> #10 0x00010a37d3dd in zend_startup_modules ()
> #11 0x00010a3287bf in php_module_startup ()
> #12 0x00010a3ef637 in php_cli_startup ()

This is done BEFORE your script starts - so nothing that you can do to stop it.

> #13 0x00010a3efff8 in main ()

Try the daemonize that I wrote about a few minutes ago.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-30 Thread Alain Williams
On Wed, Nov 30, 2011 at 12:58:26PM +0100, richard gray wrote:
> On 29/11/2011 17:16, Daniel Brown wrote:
> >On Sat, Nov 19, 2011 at 09:33, richard gray  wrote:
> >This happens because PHP is writing to STDOUT, of course, and then the 
> >command line redirection grabs that information and puts it into the 
> >file. Unfortunately, by itself, this won't work in the background, 
> >which is why you're getting the SIGTTOU (SIGnal TTy OUput). If you 
> >need to redirect the output and have it run in the background (where 
> >something like file_put_contents() or fwrite() isn't a practical 
> >option), give it a NOHUP (NO Hang-UP): nohup php test.php > test.log & 
> >This will automatically redirect STDERR to STDOUT, save for the 
> >message telling you the same. 
> 
> Thanks for your reply Daniel unfortunately nohup makes no difference the 
> script still stops with no output being logged -- and also on a 
> different machine (Ubuntu) php -f test.php >test.log 2>&1 & -- works 
> perfectly - seems to be an issue with OSX Lion and the version of PHP 
> that came with the machine -- I cannot compile my own build of PHP 
> because of this problem -> https://bugs.php.net/bug.php?id=60268 -- so I 
> am completely stuck :(

The point is that you need to completely disassociate the process from the tty.
Install the daemonize program, then use it to run your PHP script. See:

http://software.clapper.org/daemonize/

It claims to run under OSx (which is just BSD Unix).

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-30 Thread richard gray

On 23/11/2011 18:49, Alain Williams wrote:

On Wed, Nov 23, 2011 at 06:14:07PM +0100, richard gray wrote:


Reading symbols for shared libraries + done
0x000101d057ee in __ioctl ()

Any clues? To me it looks like PHP cli is trying to do some I/O but I'm
just a dumb developer... :)

ioctl on a tty is typically used to set it into single character at a time mode 
(remove stty's icanon).
It could have decided that since it is a tty then that should be set.

You need a bit more info, get a backtrace with 'where'.

Thanks for the response Alain - below is the output:-

[rich@LeMans] (/Web/scripts)> gdb --pid=3294
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug  8 20:32:45 
UTC 2011)

Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain 
conditions.

Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
/Web/scripts/3294: No such file or directory
Attaching to process 3294.
Reading symbols for shared libraries . done
Reading symbols for shared libraries 
 
done

Reading symbols for shared libraries + done
0x7fff8f8ac7ee in __ioctl ()
(gdb) where
#0  0x7fff8f8ac7ee in __ioctl ()
#1  0x7fff8f8ac1fe in ioctl ()
#2  0x7fff910a6b1c in tcsetattr ()
#3  0x00010ab05df7 in tty_end ()
#4  0x00010ab05c39 in tty_init ()
#5  0x00010aaf7261 in el_init ()
#6  0x00010aafeb8e in rl_initialize ()
#7  0x00010a3ef39a in zm_startup_readline ()
#8  0x00010a37a1c8 in zend_startup_module_ex ()
#9  0x00010a38166b in zend_hash_apply ()
#10 0x00010a37d3dd in zend_startup_modules ()
#11 0x00010a3287bf in php_module_startup ()
#12 0x00010a3ef637 in php_cli_startup ()
#13 0x00010a3efff8 in main ()


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-30 Thread richard gray

On 29/11/2011 17:16, Daniel Brown wrote:

On Sat, Nov 19, 2011 at 09:33, richard gray  wrote:
This happens because PHP is writing to STDOUT, of course, and then the 
command line redirection grabs that information and puts it into the 
file. Unfortunately, by itself, this won't work in the background, 
which is why you're getting the SIGTTOU (SIGnal TTy OUput). If you 
need to redirect the output and have it run in the background (where 
something like file_put_contents() or fwrite() isn't a practical 
option), give it a NOHUP (NO Hang-UP): nohup php test.php > test.log & 
This will automatically redirect STDERR to STDOUT, save for the 
message telling you the same. 


Thanks for your reply Daniel unfortunately nohup makes no difference the 
script still stops with no output being logged -- and also on a 
different machine (Ubuntu) php -f test.php >test.log 2>&1 & -- works 
perfectly - seems to be an issue with OSX Lion and the version of PHP 
that came with the machine -- I cannot compile my own build of PHP 
because of this problem -> https://bugs.php.net/bug.php?id=60268 -- so I 
am completely stuck :(


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-23 Thread Alain Williams
On Wed, Nov 23, 2011 at 06:14:07PM +0100, richard gray wrote:

> Reading symbols for shared libraries + done
> 0x000101d057ee in __ioctl ()
> 
> Any clues? To me it looks like PHP cli is trying to do some I/O but I'm 
> just a dumb developer... :)

ioctl on a tty is typically used to set it into single character at a time mode 
(remove stty's icanon).
It could have decided that since it is a tty then that should be set.

You need a bit more info, get a backtrace with 'where'.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-23 Thread richard gray

On 23/11/2011 11:05, Laruence wrote:

Hi:
   I mean,  do you built your php with readline support, or do you load
readline.so into PHP?

   if so, remove it, then try again.

   and you also can use:
   gdb --pid={the pid of the stopped php}

   then you will find where the php  hangs.

thanks
I didn't build PHP as it fails to make -- see 
https://bugs.php.net/bug.php?id=60268 so I am stuck with the PHP build 
provided by Apple... :(


Here's what gdb says

[rich@LeMans] (/web/scripts)> php -f test.php >test.log 2>&1 &
[1] 3513
[rich@LeMans] (/web/scripts)>
[1]+  Stopped php -f test.php > test.log 2>&1
[rich@LeMans] (/web/scripts)> gdb --pid 3513
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug  8 20:32:45 
UTC 2011)

Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain 
conditions.

Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
/Web/scripts/3513: No such file or directory
Attaching to process 3513.
Reading symbols for shared libraries . done
Reading symbols for shared libraries 
 
done

Reading symbols for shared libraries + done
0x000101d057ee in __ioctl ()

Any clues? To me it looks like PHP cli is trying to do some I/O but I'm 
just a dumb developer... :)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-23 Thread Laruence
Hi:
  I mean,  do you built your php with readline support, or do you load
readline.so into PHP?

  if so, remove it, then try again.

  and you also can use:
  gdb --pid={the pid of the stopped php}

  then you will find where the php  hangs.

thanks

On Wed, Nov 23, 2011 at 1:04 AM, richard gray  wrote:
> On 22/11/2011 05:51, Laruence wrote:
>>
>> did you run php with readline?  try run the script without php-readline.
>>
>> thanks
>
> No - the script was just a basic string echo - no readline was involved.
>



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-22 Thread richard gray

On 22/11/2011 05:51, Laruence wrote:

did you run php with readline?  try run the script without php-readline.

thanks

No - the script was just a basic string echo - no readline was involved.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-21 Thread Laruence
On Sat, Nov 19, 2011 at 11:27 PM, richard gray  wrote:
>
>> Laruence, while that may be a helpful answer to a few people in the know,
I think a clue is better, leave some space for the people to dance.  :)
>> just replying back with a single line like that isn't really going to help
>> the people who are having this problem. At least explain why you suggested
>> that, or what it does for those on the list that don't know, especially as
>> it's not a PHP thing, it's a Unix command thing.
>>
>> Richard, some more info on the command Laruence mentioned can be found at
>> http://docstore.mik.ua/orelly/unix/upt/ch12_07.htm which explains it in more
>> detail.
>>
> not sure this is relevant as my script is not trying to write to the
> terminal the >test.log 2>&1 is sending stdout and stderr to the log file not
> the tty...

did you run php with readline?  try run the script without php-readline.

thanks
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-21 Thread Richard Quadling
On 19 November 2011 14:33, richard gray  wrote:
> Hi all
>
> Hope someone can help me with a weird issue I have...
>
> 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
>
> OS
> Mac OS X Lion 10.7.2
>
> PHP
> PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep  8 2011 19:34:00)
> Copyright (c) 1997-2011 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
>
> I created a basic script  test.php
>
> 
>
> Here are the results of various tests:-
>
> Test 1) php -f test.php  (Hello world gets displayed)
> Test 2) php -f test.php >test.log 2>&1 (Hello world gets put into test.log)
> Test 3) 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 open
>
> It is something to do with php because a similar shell script gets executed
> no problems in the background...
>
> This has me stumped ... any ideas?
>
> TIA
> Rich
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I've seen this ...

php script.php 1>nul 2>nul

Not sure how effective it is. But the code is tagged as a "fire and
forget" mechanism.

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc : Fantasy Shopper
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea :
fan.sh/6/370

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-19 Thread richard gray


Laruence, while that may be a helpful answer to a few people in the 
know, just replying back with a single line like that isn't really 
going to help the people who are having this problem. At least explain 
why you suggested that, or what it does for those on the list that 
don't know, especially as it's not a PHP thing, it's a Unix command thing.


Richard, some more info on the command Laruence mentioned can be found 
at http://docstore.mik.ua/orelly/unix/upt/ch12_07.htm which explains 
it in more detail.


not sure this is relevant as my script is not trying to write to the 
terminal the >test.log 2>&1 is sending stdout and stderr to the log file 
not the tty...



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-19 Thread richard gray

On 19/11/2011 16:09, Laruence wrote:

$ stty -tostop


makes no difference

# stty -tostop
# php -f test.php >test.log 2>&1 &
# jobs
# [1]+  Stopped(SIGTTOU)php -f test.php > test.log 2>&1

Any other ideas?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-19 Thread Ashley Sheridan
On Sat, 2011-11-19 at 23:09 +0800, Laruence wrote:

> $ stty -tostop
> 
> thanks
> 
> On Sat, Nov 19, 2011 at 10:33 PM, richard gray  wrote:
> > Hi all
> >
> > Hope someone can help me with a weird issue I have...
> >
> > 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
> >
> > OS
> > Mac OS X Lion 10.7.2
> >
> > PHP
> > PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep  8 2011 19:34:00)
> > Copyright (c) 1997-2011 The PHP Group
> > Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
> >
> > I created a basic script  test.php
> >
> > 
> >
> > Here are the results of various tests:-
> >
> > Test 1) php -f test.php  (Hello world gets displayed)
> > Test 2) php -f test.php >test.log 2>&1 (Hello world gets put into test.log)
> > Test 3) 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 open
> >
> > It is something to do with php because a similar shell script gets executed
> > no problems in the background...
> >
> > This has me stumped ... any ideas?
> >
> > TIA
> > Rich
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> 
> -- 
> Laruence  Xinchen Hui
> http://www.laruence.com/
> 


Laruence, while that may be a helpful answer to a few people in the
know, just replying back with a single line like that isn't really going
to help the people who are having this problem. At least explain why you
suggested that, or what it does for those on the list that don't know,
especially as it's not a PHP thing, it's a Unix command thing.

Richard, some more info on the command Laruence mentioned can be found
at http://docstore.mik.ua/orelly/unix/upt/ch12_07.htm which explains it
in more detail.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] PHP script won't run in the background

2011-11-19 Thread richard gray

Hi all

Hope someone can help me with a weird issue I have...

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


OS
Mac OS X Lion 10.7.2

PHP
PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep  8 2011 19:34:00)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

I created a basic script  test.php



Here are the results of various tests:-

Test 1) php -f test.php  (Hello world gets displayed)
Test 2) php -f test.php >test.log 2>&1 (Hello world gets put into test.log)
Test 3) 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 open


It is something to do with php because a similar shell script gets 
executed no problems in the background...


This has me stumped ... any ideas?

TIA
Rich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP script won't run in the background

2011-11-19 Thread Laruence
$ stty -tostop

thanks

On Sat, Nov 19, 2011 at 10:33 PM, richard gray  wrote:
> Hi all
>
> Hope someone can help me with a weird issue I have...
>
> 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
>
> OS
> Mac OS X Lion 10.7.2
>
> PHP
> PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep  8 2011 19:34:00)
> Copyright (c) 1997-2011 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
>
> I created a basic script  test.php
>
> 
>
> Here are the results of various tests:-
>
> Test 1) php -f test.php  (Hello world gets displayed)
> Test 2) php -f test.php >test.log 2>&1 (Hello world gets put into test.log)
> Test 3) 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 open
>
> It is something to do with php because a similar shell script gets executed
> no problems in the background...
>
> This has me stumped ... any ideas?
>
> TIA
> Rich
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php