php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60483 stream_select only selects STDIN if present in read array
Submitted: 2011-12-09 15:25 UTC Modified: 2011-12-22 15:37 UTC
From: vmiszczak at ankama dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.3.8 OS: Linux/Debian x64
Private report: No CVE-ID: None
 [2011-12-09 15:25 UTC] vmiszczak at ankama dot com
Description:
------------
I'm writing a data multiplexer PHP CLI script that takes data from STDIN and 
dispatchs 
those data on programs opened with proc_open().
I'm using stream_select() to see which descriptor has data. The read array I'm 
using contains STDIN and the output streams from programs opened with proc_open() 
(the classic $pipes[1] from proc_open() descriptorspec). Those programs write on 
their stdout as soon as there is data on their stdin (actually those programs are 
PHP scripts echoing input). If STDIN remains in the read set, stream_select 
returns only STDIN as readable and never returns any of the programs output 
streams.
As soon as STDIN is removed from the read set, stream_select behave normaly and 
selects the output streams that are ready.

Expected result:
----------------
I'm expecting all my ready streams to be returned, even if STDIN is present in the 
set.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-11 15:52 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2011-12-11 15:52 UTC] cataphract@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2011-12-12 12:59 UTC] vmiszczak at ankama dot com
-Status: Feedback +Status: Open
 [2011-12-12 12:59 UTC] vmiszczak at ankama dot com
Here is a simple dummy.php that can be used as a program opened with proc_open() 
:
http://pastebin.com/78KEpbBB

Here is a way to show the problem :
http://pastebin.com/aNZK6DBv

If you launch this script simply using "php bug.php" and sending data by hand, 
no problem, it will do the job.
If you launch this script using "php bug.php < lines.txt" where lines.txt is a 
text file containing lines, the response from the proc_opened process happens 
only when there is no more data on STDIN. That's not nice because I want to 
create a real time forwarder.

I may have missed something with the buffering system but it looks like a 
problem.
 [2011-12-22 15:25 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2011-12-22 15:25 UTC] cataphract@php.net
This is just a timing issue. For instance, when I call sleep() after calling "$this->startPingPongProgram();", I get:

STDIN is blocking
Program STDIN is blocking
Program STDOUT is blocking
Program STDERR is blocking
We have 1 descriptor(s) ready :
Array
(
    [0] => Resource id #1
)
We have 1 descriptor(s) ready :
Array
(
    [0] => Resource id #1
)
We have 1 descriptor(s) ready :
Array
(
    [0] => Resource id #1
)
We have 2 descriptor(s) ready :
Array
(
    [0] => Resource id #5
    [1] => Resource id #1
)
We got data on Resource id #5 : !!! line 1
 !!!
!!! line 2
 !!!
!!! line 3
 !!!

line is false
Program's STDIN closed
Program's STDOUT closed
Program's STDERR closed
Program terminated

Which disproves your thesis. You'll have to coordinate the processes.

Thanks for the report, but I'm marking it bogus.
 [2011-12-22 15:37 UTC] vmiszczak at ankama dot com
Hello,
I think you did not test as you should.
You stopped feeding STDIN and you got the expected response.
If you feed STDIN with a lot of data (say several MB of lines), you should see the 
problem. Doing so should show you that you can live multiples seconds without 
selecting other data than STDIN.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC