Bug #51160 [Com]: Exec family of functions runs a script piped into 'head' too until script end

2012-06-05 Thread mrvanes at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=51160edit=1

 ID: 51160
 Comment by: mrvanes at gmail dot com
 Reported by:poehler at interworx dot com
 Summary:Exec family of functions runs a script piped into
 'head' too until script end
 Status: Not a bug
 Type:   Bug
 Package:*General Issues
 Operating System:   CentOS 5.4
 PHP Version:5.2.13
 Block user comment: N
 Private report: N

 New Comment:

The above proc_open solution does work (better) for the `ls | ls | ls | ls | 
ls` 
test case, but not my real-world problem. This is becoming a nasty bug(?) to 
work 
around.


Previous Comments:

[2012-05-09 09:27:50] mrvanes at gmail dot com

Ok, so I finally think to have cracked the problem:
This seem to be the equivalent of exec('cmd', $output) that does not create a 
broken pipe:

$p = proc_open(ls | ls | ls | ls | ls | ls | ls | echo `date`  foobar | ls,
  array(
array(pipe,r),
array(pipe,w),
array(pipe,w)
  ),
  $pipes
);
while (($buffer = fgets($pipes[1])) !== false) $output[] = trim($buffer);
foreach ($pipes as $pipe) fclose($pipe);
if (isset($output)) print_r($output);

There is no broken pipe and the file foobar now contains the output of date.


[2012-05-09 07:09:14] mrvanes at gmail dot com

I must correct: the SIGPIPE sighandler does suppress the message but does not 
solve the problem! The command that generates the broken pipe fails.


[2012-05-07 08:39:34] mrvanes at gmail dot com

I was encountering a similar problem too and for some reason Mike's hint 
(registering an empty/exit function on the SIGPIPE signal) solved the problem 
for 
me.
The only problem I now have is racking my brains over WHY?! Is this discussed 
somewhere so I can read up on the given solution?


[2012-01-19 12:26:16] burek021 at gmail dot com

Just to say, my problem somehow got misteriosly solved. I don't know exactly 
what was the culprit, but I know I've messed around with ulimit and with 
apache2.conf:
IfModule mpm_prefork_module
StartServers  5
MinSpareServers   5
MaxSpareServers 100
MaxClients  150
MaxRequestsPerChild   0
/IfModule
More details here (if needed): 
http://www.linuxquestions.org/questions/showthread.php?p=4577927


[2012-01-18 21:59:26] burek021 at gmail dot com

I also have this issue. I've tried to test a simple example on several of our 
web hosting machines and all of them have this issue present.

Simple test. Create a php file (test.php) with this content:
==
?php
shell_exec('ls | ls | ls | ls' );
==
and then run: php -f test.php 21
you should get the error like: ls: write error: Broken pipe
almost every time you run that command.

I'm not sure what's the reason for this, but I'm pretty sure it's the bug, 
since the bash/sh doesn't ever raise that error no matter how many ls'es we put 
into the pipe.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=51160


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51160edit=1


Bug #51160 [Com]: Exec family of functions runs a script piped into 'head' too until script end

2012-05-09 Thread mrvanes at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=51160edit=1

 ID: 51160
 Comment by: mrvanes at gmail dot com
 Reported by:poehler at interworx dot com
 Summary:Exec family of functions runs a script piped into
 'head' too until script end
 Status: Not a bug
 Type:   Bug
 Package:*General Issues
 Operating System:   CentOS 5.4
 PHP Version:5.2.13
 Block user comment: N
 Private report: N

 New Comment:

I must correct: the SIGPIPE sighandler does suppress the message but does not 
solve the problem! The command that generates the broken pipe fails.


Previous Comments:

[2012-05-07 08:39:34] mrvanes at gmail dot com

I was encountering a similar problem too and for some reason Mike's hint 
(registering an empty/exit function on the SIGPIPE signal) solved the problem 
for 
me.
The only problem I now have is racking my brains over WHY?! Is this discussed 
somewhere so I can read up on the given solution?


[2012-01-19 12:26:16] burek021 at gmail dot com

Just to say, my problem somehow got misteriosly solved. I don't know exactly 
what was the culprit, but I know I've messed around with ulimit and with 
apache2.conf:
IfModule mpm_prefork_module
StartServers  5
MinSpareServers   5
MaxSpareServers 100
MaxClients  150
MaxRequestsPerChild   0
/IfModule
More details here (if needed): 
http://www.linuxquestions.org/questions/showthread.php?p=4577927


[2012-01-18 21:59:26] burek021 at gmail dot com

I also have this issue. I've tried to test a simple example on several of our 
web hosting machines and all of them have this issue present.

Simple test. Create a php file (test.php) with this content:
==
?php
shell_exec('ls | ls | ls | ls' );
==
and then run: php -f test.php 21
you should get the error like: ls: write error: Broken pipe
almost every time you run that command.

I'm not sure what's the reason for this, but I'm pretty sure it's the bug, 
since the bash/sh doesn't ever raise that error no matter how many ls'es we put 
into the pipe.


[2010-12-07 21:57:02] sirjava at gmail dot com

I'm confused.  If the exec family of functions is designed to execute something 
as if executed from a shell, and the command executes properly from a shell, 
but not in php... how is this not a php bug?


[2010-05-17 11:21:33] m...@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

$ cat 51160.php 
? 

pcntl_signal(SIGPIPE, function() { exit; });

passthru (/bin/sh 51160.sh | head -n1);




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=51160


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51160edit=1


Bug #51160 [Com]: Exec family of functions runs a script piped into 'head' too until script end

2012-05-09 Thread mrvanes at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=51160edit=1

 ID: 51160
 Comment by: mrvanes at gmail dot com
 Reported by:poehler at interworx dot com
 Summary:Exec family of functions runs a script piped into
 'head' too until script end
 Status: Not a bug
 Type:   Bug
 Package:*General Issues
 Operating System:   CentOS 5.4
 PHP Version:5.2.13
 Block user comment: N
 Private report: N

 New Comment:

Ok, so I finally think to have cracked the problem:
This seem to be the equivalent of exec('cmd', $output) that does not create a 
broken pipe:

$p = proc_open(ls | ls | ls | ls | ls | ls | ls | echo `date`  foobar | ls,
  array(
array(pipe,r),
array(pipe,w),
array(pipe,w)
  ),
  $pipes
);
while (($buffer = fgets($pipes[1])) !== false) $output[] = trim($buffer);
foreach ($pipes as $pipe) fclose($pipe);
if (isset($output)) print_r($output);

There is no broken pipe and the file foobar now contains the output of date.


Previous Comments:

[2012-05-09 07:09:14] mrvanes at gmail dot com

I must correct: the SIGPIPE sighandler does suppress the message but does not 
solve the problem! The command that generates the broken pipe fails.


[2012-05-07 08:39:34] mrvanes at gmail dot com

I was encountering a similar problem too and for some reason Mike's hint 
(registering an empty/exit function on the SIGPIPE signal) solved the problem 
for 
me.
The only problem I now have is racking my brains over WHY?! Is this discussed 
somewhere so I can read up on the given solution?


[2012-01-19 12:26:16] burek021 at gmail dot com

Just to say, my problem somehow got misteriosly solved. I don't know exactly 
what was the culprit, but I know I've messed around with ulimit and with 
apache2.conf:
IfModule mpm_prefork_module
StartServers  5
MinSpareServers   5
MaxSpareServers 100
MaxClients  150
MaxRequestsPerChild   0
/IfModule
More details here (if needed): 
http://www.linuxquestions.org/questions/showthread.php?p=4577927


[2012-01-18 21:59:26] burek021 at gmail dot com

I also have this issue. I've tried to test a simple example on several of our 
web hosting machines and all of them have this issue present.

Simple test. Create a php file (test.php) with this content:
==
?php
shell_exec('ls | ls | ls | ls' );
==
and then run: php -f test.php 21
you should get the error like: ls: write error: Broken pipe
almost every time you run that command.

I'm not sure what's the reason for this, but I'm pretty sure it's the bug, 
since the bash/sh doesn't ever raise that error no matter how many ls'es we put 
into the pipe.


[2010-12-07 21:57:02] sirjava at gmail dot com

I'm confused.  If the exec family of functions is designed to execute something 
as if executed from a shell, and the command executes properly from a shell, 
but not in php... how is this not a php bug?




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=51160


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51160edit=1


Bug #51160 [Com]: Exec family of functions runs a script piped into 'head' too until script end

2012-05-07 Thread mrvanes at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=51160edit=1

 ID: 51160
 Comment by: mrvanes at gmail dot com
 Reported by:poehler at interworx dot com
 Summary:Exec family of functions runs a script piped into
 'head' too until script end
 Status: Not a bug
 Type:   Bug
 Package:*General Issues
 Operating System:   CentOS 5.4
 PHP Version:5.2.13
 Block user comment: N
 Private report: N

 New Comment:

I was encountering a similar problem too and for some reason Mike's hint 
(registering an empty/exit function on the SIGPIPE signal) solved the problem 
for 
me.
The only problem I now have is racking my brains over WHY?! Is this discussed 
somewhere so I can read up on the given solution?


Previous Comments:

[2012-01-19 12:26:16] burek021 at gmail dot com

Just to say, my problem somehow got misteriosly solved. I don't know exactly 
what was the culprit, but I know I've messed around with ulimit and with 
apache2.conf:
IfModule mpm_prefork_module
StartServers  5
MinSpareServers   5
MaxSpareServers 100
MaxClients  150
MaxRequestsPerChild   0
/IfModule
More details here (if needed): 
http://www.linuxquestions.org/questions/showthread.php?p=4577927


[2012-01-18 21:59:26] burek021 at gmail dot com

I also have this issue. I've tried to test a simple example on several of our 
web hosting machines and all of them have this issue present.

Simple test. Create a php file (test.php) with this content:
==
?php
shell_exec('ls | ls | ls | ls' );
==
and then run: php -f test.php 21
you should get the error like: ls: write error: Broken pipe
almost every time you run that command.

I'm not sure what's the reason for this, but I'm pretty sure it's the bug, 
since the bash/sh doesn't ever raise that error no matter how many ls'es we put 
into the pipe.


[2010-12-07 21:57:02] sirjava at gmail dot com

I'm confused.  If the exec family of functions is designed to execute something 
as if executed from a shell, and the command executes properly from a shell, 
but not in php... how is this not a php bug?


[2010-05-17 11:21:33] m...@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

$ cat 51160.php 
? 

pcntl_signal(SIGPIPE, function() { exit; });

passthru (/bin/sh 51160.sh | head -n1);


[2010-02-26 21:22:04] binarycleric at gmail dot com

Just wanted to confirm that this also occurs on Mac OS 10.6 using version PHP 
5.3.0.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=51160


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51160edit=1


Bug #51160 [Com]: Exec family of functions runs a script piped into 'head' too until script end

2012-01-19 Thread burek021 at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=51160edit=1

 ID: 51160
 Comment by: burek021 at gmail dot com
 Reported by:poehler at interworx dot com
 Summary:Exec family of functions runs a script piped into
 'head' too until script end
 Status: Bogus
 Type:   Bug
 Package:*General Issues
 Operating System:   CentOS 5.4
 PHP Version:5.2.13
 Block user comment: N
 Private report: N

 New Comment:

Just to say, my problem somehow got misteriosly solved. I don't know exactly 
what was the culprit, but I know I've messed around with ulimit and with 
apache2.conf:
IfModule mpm_prefork_module
StartServers  5
MinSpareServers   5
MaxSpareServers 100
MaxClients  150
MaxRequestsPerChild   0
/IfModule
More details here (if needed): 
http://www.linuxquestions.org/questions/showthread.php?p=4577927


Previous Comments:

[2012-01-18 21:59:26] burek021 at gmail dot com

I also have this issue. I've tried to test a simple example on several of our 
web hosting machines and all of them have this issue present.

Simple test. Create a php file (test.php) with this content:
==
?php
shell_exec('ls | ls | ls | ls' );
==
and then run: php -f test.php 21
you should get the error like: ls: write error: Broken pipe
almost every time you run that command.

I'm not sure what's the reason for this, but I'm pretty sure it's the bug, 
since the bash/sh doesn't ever raise that error no matter how many ls'es we put 
into the pipe.


[2010-12-07 21:57:02] sirjava at gmail dot com

I'm confused.  If the exec family of functions is designed to execute something 
as if executed from a shell, and the command executes properly from a shell, 
but not in php... how is this not a php bug?


[2010-05-17 11:21:33] m...@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

$ cat 51160.php 
? 

pcntl_signal(SIGPIPE, function() { exit; });

passthru (/bin/sh 51160.sh | head -n1);


[2010-02-26 21:22:04] binarycleric at gmail dot com

Just wanted to confirm that this also occurs on Mac OS 10.6 using version PHP 
5.3.0.


[2010-02-26 21:15:40] poehler at interworx dot com

Description:

See reproduce code and expected / actual result sections for details.

Short story is when exec'ing with a pipe to 'head', we're getting unexpected 
results.

I'm aware this may be 'correct' behavior, by some definition, but for the life 
of me I can't figure out where this behavior is documented, if that is the 
case.  So if that is the case, please point me in the right direction, if you 
could be so kind.



Reproduce code:
---
test.sh:
=
#!/bin/sh

for i in 1 2 3 4 5
do
   echo Welcome $i times
   sleep 1
done
==


test.php:
==
?
passthru( '/bin/sh test.sh | head -n1' );

==




Expected result:

Here is the output of running the same command at the shell, which is correct.
==
[root@me]# time /bin/sh test.sh | head -n1
Welcome 1 times

real0m1.030s
user0m0.002s
sys 0m0.027s
==
And I would expect identical (save minor timing differences) when test.php is 
run.

Actual result:
--
[root@me]# php test.php
Welcome 1 times
test.sh: line 5: echo: write error: Broken pipe
test.sh: line 5: echo: write error: Broken pipe
test.sh: line 5: echo: write error: Broken pipe
test.sh: line 5: echo: write error: Broken pipe

real0m5.191s
user0m0.002s
sys 0m0.038s

Note that this took 5 seconds instead of 1.






-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51160edit=1


Bug #51160 [Com]: Exec family of functions runs a script piped into 'head' too until script end

2012-01-18 Thread burek021 at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=51160edit=1

 ID: 51160
 Comment by: burek021 at gmail dot com
 Reported by:poehler at interworx dot com
 Summary:Exec family of functions runs a script piped into
 'head' too until script end
 Status: Bogus
 Type:   Bug
 Package:*General Issues
 Operating System:   CentOS 5.4
 PHP Version:5.2.13
 Block user comment: N
 Private report: N

 New Comment:

I also have this issue. I've tried to test a simple example on several of our 
web hosting machines and all of them have this issue present.

Simple test. Create a php file (test.php) with this content:
==
?php
shell_exec('ls | ls | ls | ls' );
==
and then run: php -f test.php 21
you should get the error like: ls: write error: Broken pipe
almost every time you run that command.

I'm not sure what's the reason for this, but I'm pretty sure it's the bug, 
since the bash/sh doesn't ever raise that error no matter how many ls'es we put 
into the pipe.


Previous Comments:

[2010-12-07 21:57:02] sirjava at gmail dot com

I'm confused.  If the exec family of functions is designed to execute something 
as if executed from a shell, and the command executes properly from a shell, 
but not in php... how is this not a php bug?


[2010-05-17 11:21:33] m...@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

$ cat 51160.php 
? 

pcntl_signal(SIGPIPE, function() { exit; });

passthru (/bin/sh 51160.sh | head -n1);


[2010-02-26 21:22:04] binarycleric at gmail dot com

Just wanted to confirm that this also occurs on Mac OS 10.6 using version PHP 
5.3.0.


[2010-02-26 21:15:40] poehler at interworx dot com

Description:

See reproduce code and expected / actual result sections for details.

Short story is when exec'ing with a pipe to 'head', we're getting unexpected 
results.

I'm aware this may be 'correct' behavior, by some definition, but for the life 
of me I can't figure out where this behavior is documented, if that is the 
case.  So if that is the case, please point me in the right direction, if you 
could be so kind.



Reproduce code:
---
test.sh:
=
#!/bin/sh

for i in 1 2 3 4 5
do
   echo Welcome $i times
   sleep 1
done
==


test.php:
==
?
passthru( '/bin/sh test.sh | head -n1' );

==




Expected result:

Here is the output of running the same command at the shell, which is correct.
==
[root@me]# time /bin/sh test.sh | head -n1
Welcome 1 times

real0m1.030s
user0m0.002s
sys 0m0.027s
==
And I would expect identical (save minor timing differences) when test.php is 
run.

Actual result:
--
[root@me]# php test.php
Welcome 1 times
test.sh: line 5: echo: write error: Broken pipe
test.sh: line 5: echo: write error: Broken pipe
test.sh: line 5: echo: write error: Broken pipe
test.sh: line 5: echo: write error: Broken pipe

real0m5.191s
user0m0.002s
sys 0m0.038s

Note that this took 5 seconds instead of 1.






-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51160edit=1


Bug #51160 [Com]: Exec family of functions runs a script piped into 'head' too until script end

2010-12-07 Thread sirjava at gmail dot com
Edit report at http://bugs.php.net/bug.php?id=51160edit=1

 ID: 51160
 Comment by: sirjava at gmail dot com
 Reported by:poehler at interworx dot com
 Summary:Exec family of functions runs a script piped into
 'head' too until script end
 Status: Bogus
 Type:   Bug
 Package:*General Issues
 Operating System:   CentOS 5.4
 PHP Version:5.2.13
 Block user comment: N
 Private report: N

 New Comment:

I'm confused.  If the exec family of functions is designed to execute
something as if executed from a shell, and the command executes properly
from a shell, but not in php... how is this not a php bug?


Previous Comments:

[2010-05-17 11:21:33] m...@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

$ cat 51160.php 

? 



pcntl_signal(SIGPIPE, function() { exit; });



passthru (/bin/sh 51160.sh | head -n1);


[2010-02-26 21:22:04] binarycleric at gmail dot com

Just wanted to confirm that this also occurs on Mac OS 10.6 using
version PHP 5.3.0.


[2010-02-26 21:15:40] poehler at interworx dot com

Description:

See reproduce code and expected / actual result sections for details.



Short story is when exec'ing with a pipe to 'head', we're getting
unexpected results.



I'm aware this may be 'correct' behavior, by some definition, but for
the life of me I can't figure out where this behavior is documented, if
that is the case.  So if that is the case, please point me in the right
direction, if you could be so kind.





Reproduce code:
---
test.sh:

=

#!/bin/sh



for i in 1 2 3 4 5

do

   echo Welcome $i times

   sleep 1

done

==





test.php:

==

?

passthru( '/bin/sh test.sh | head -n1' );



==







Expected result:

Here is the output of running the same command at the shell, which is
correct.

==

[r...@me]# time /bin/sh test.sh | head -n1

Welcome 1 times



real0m1.030s

user0m0.002s

sys 0m0.027s

==

And I would expect identical (save minor timing differences) when
test.php is run.

Actual result:
--
[r...@me]# php test.php

Welcome 1 times

test.sh: line 5: echo: write error: Broken pipe

test.sh: line 5: echo: write error: Broken pipe

test.sh: line 5: echo: write error: Broken pipe

test.sh: line 5: echo: write error: Broken pipe



real0m5.191s

user0m0.002s

sys 0m0.038s



Note that this took 5 seconds instead of 1.






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51160edit=1