php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36030 stream_set_timeout() does not work for php://stdin
Submitted: 2006-01-16 10:56 UTC Modified: 2011-04-08 18:14 UTC
Votes:29
Avg. Score:4.2 ± 1.0
Reproduced:26 of 26 (100.0%)
Same Version:14 (53.8%)
Same OS:17 (65.4%)
From: silencer at inbox dot ru Assigned:
Status: Open Package: Streams related
PHP Version: 5.3 OS: *
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-01-16 10:56 UTC] silencer at inbox dot ru
Description:
------------
stream_set_timeout can't be used for php://stdin (PHP executed as CGI, not Apache module). 

Bug #22837 describe same problem for PHP4 and promises "better support" in PHP5, but still don't working.

Reproduce code:
---------------
<?php
$fp=fopen('php://stdin','r'); 
stream_set_timeout($fp,1) or die ('Failed'); 
echo 'Success';
?>

Expected result:
----------------
output "Success"

Actual result:
--------------
output "Failed"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-30 16:20 UTC] silencer at inbox dot ru
Still don't working with
PHP 5.2.10-pl0-gentoo (cli)
 [2009-11-11 04:20 UTC] voidroid at gmail dot com
Still does not work with PHP 5.3.0

Using the following as an alternative:

$current_choice = trim(`bash -c "read -s -t 1 -n 1 ANS; echo \\\$ANS"`);

It times out after 1 second but I would prefer less as I want a quicker refresh!
 [2011-04-08 18:14 UTC] jani@php.net
-Package: Feature/Change Request +Package: Streams related -Operating System: Gentoo Linux +Operating System: * -PHP Version: 5.2.10 +PHP Version: 5.3
 [2012-01-20 19:40 UTC] an0nym at narod dot ru
Still isn't working on PHP 5.3.9. 

[an0nym@localhost ~]$ php -v
PHP 5.3.9 (cli) (built: Jan 11 2012 17:59:59) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
[an0nym@localhost ~]$ cat test.php 
<?php
var_dump(stream_set_timeout(STDIN, 5));
[an0nym@localhost ~]$ php test.php 
bool(false)
[an0nym@localhost ~]$ 

Workaround.

[an0nym@localhost ~]$ cat input.php 
<?php
for ($i = 0;; ++$i)
{
  printf("%d\n", $i);
  sleep($i);
}
[an0nym@localhost ~]$ cat output.php 
<?php
stream_set_blocking(STDIN, 0);
$rss = array(STDIN);
$wss = $ess = null;
while (stream_select($rss, $wss, $ess, $argv[1]))
{
  printf("%f\n", microtime(true));
  echo stream_get_contents(STDIN);
}
printf("%f\n", microtime(true));
[an0nym@localhost ~]$ time php input.php | php output.php 5
1327087817.988219
0
1
1327087818.988345
2
1327087820.988437
3
1327087823.988534
4
1327087827.988655
5
1327087832.988771
6
1327087837.993888

real	0m21.023s
user	0m0.017s
sys	0m0.020s
[an0nym@localhost ~]$
 [2013-02-03 15:50 UTC] david at davidsteinsland dot net
Bug exists in PHP 5.4.6 also.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 10:03:03 2014 UTC