Edit report at http://bugs.php.net/bug.php?id=51160&edit=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



real    0m1.030s

user    0m0.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



real    0m5.191s

user    0m0.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=51160&edit=1

Reply via email to