Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何实施";随时按Q键退出“;在PHP中_Php - Fatal编程技术网

如何实施";随时按Q键退出“;在PHP中

如何实施";随时按Q键退出“;在PHP中,php,Php,我有一个基于终端的php程序,它基本上只是在一个大的for循环中运行,做了很多事情,然后退出。我希望能够中断循环,暂停或退出应用程序。目前,我必须按^C退出应用程序(或从另一个终端屏幕将其杀死)。有什么想法我可以实现这一点吗 Running program... [Press Q to quit and <spacebar> to pause at any time] text text text ... more text scrolling by 正在运行程序。。。 [按Q键

我有一个基于终端的php程序,它基本上只是在一个大的for循环中运行,做了很多事情,然后退出。我希望能够中断循环,暂停或退出应用程序。目前,我必须按^C退出应用程序(或从另一个终端屏幕将其杀死)。有什么想法我可以实现这一点吗

Running program... 
[Press Q to quit and <spacebar> to pause at any time]
text
text
text
...
more text scrolling by
正在运行程序。。。
[按Q键退出并随时暂停]
文本
文本
文本
...
更多文本滚动
我知道如何退出和暂停,这很简单,但我不知道如何在执行大量其他功能时监视输入

多谢

在这里找到了答案:

感谢上面的评论者,他们给了我一些搜索参数,让我最终得到正确的答案

解决方案为流\集\阻塞,如下图所示:

<?php
  $stdin = fopen('php://stdin', 'r');
  stream_set_blocking ( $stdin , 0 );

  for( $x=0; $x <=10; $x++) {
  echo "$x\n";

  $line = fgets($stdin);  //Doesn't wait for input because blocking is turned off!
  if (! empty($line)) {
        die();
  }
}
?>

help mate。。。我相信他可能在尝试类似的事情。检查非常好的解决方案。