It seems this function is not blocking anymore:
<?php
do {
readline_callback_read_char();
$str = readline_info('line_buffer');
echo '.';
} while (strlen($str) < 10);
echo PHP_EOL . $str . PHP_EOL;
?>
PHP - Manual: readline_callback_read_char
2024-12-21
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
readline_callback_read_char — 当一个行被接收时读取一个字符并且通知 readline 调用回调函数
读取用户输入中的一个字符.当一行被接收时,这个函数将通知 readline 调用使用 readline_callback_handler_install() 安装的回调函数接口,并且 这一个行已经准备输入.
没有返回值。
See readline_callback_handler_install() for an example of how to use the readline callback interface.
It seems this function is not blocking anymore:
<?php
do {
readline_callback_read_char();
$str = readline_info('line_buffer');
echo '.';
} while (strlen($str) < 10);
echo PHP_EOL . $str . PHP_EOL;
?>
Note that this function is blocking if there is no character to read
If you don`t want to get blocked, you should use the trick with stream_select()
It also only reads one char per call,
So if something else in your script is blocking,
you`ve got a problem
官方地址:https://www.php.net/manual/en/function.readline-callback-read-char.php