Edit report at https://bugs.php.net/bug.php?id=36030&edit=1

 ID:                 36030
 Comment by:         an0nym at narod dot ru
 Reported by:        silencer at inbox dot ru
 Summary:            stream_set_timeout() does not work for php://stdin
 Status:             Open
 Type:               Feature/Change Request
 Package:            Streams related
 Operating System:   *
 PHP Version:        5.3
 Block user comment: N
 Private report:     N

 New Comment:

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 ~]$


Previous Comments:
------------------------------------------------------------------------
[2009-11-11 04:20:35] 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!

------------------------------------------------------------------------
[2009-06-30 16:20:59] silencer at inbox dot ru

Still don't working with
PHP 5.2.10-pl0-gentoo (cli)

------------------------------------------------------------------------
[2006-01-16 10:56:22] 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"


------------------------------------------------------------------------



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

Reply via email to