PHP: 如何跟踪没有输入数据的超时?

PHP: How to track the timeout of the absence of input data?

有从 STDIN 接收输入行的代码:

#!/usr/bin/php
<?php
while (false !== ($line = fgets(STDIN))) {
      if (preg_match('/start/',$line)) {
         echo $line , "\n";
      }
}
?>

我的问题是:如何跟踪输入数据缺失1分钟的超时时间,并在情况下通知?

我使用这里 [PHP CLI - Ask for User Input or Perform Action after a Period of Time

的 hek2mgl 答案解决了我的问题

这是我的代码:

#!/usr/bin/php
<?php
echo "input something ... (5 sec)\n";
$stdin = fopen('php://stdin', 'r');

while(true) {
$read = array($stdin);
$write = $except = array();
$timeout = 5;

    if(stream_select($read, $write, $except, $timeout)) {
          $line = fgets($stdin);
          if (preg_match('/start/',$line)) {
                echo $line , "\n";
          }
    } else {
       echo "you typed nothing\n";
    }
}
?>