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: 2015-01-09 00:04 UTC
Votes:31
Avg. Score:4.2 ± 1.0
Reproduced:28 of 28 (100.0%)
Same Version:15 (53.6%)
Same OS:19 (67.9%)
From: silencer at inbox dot ru Assigned:
Status: Duplicate Package: Streams related
PHP Version: 5.3 OS: *
Private report: No CVE-ID: None
 [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

Pull Requests

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.
 [2015-01-09 00:04 UTC] ajf@php.net
-Status: Open +Status: Duplicate
 [2015-01-09 00:04 UTC] ajf@php.net
Basically a duplicate of: https://bugs.php.net/bug.php?id=34972
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC