小编leo*_*108的帖子

PHP Readline: Get a new prompt on SIGINT

I'm writing a php cli interactive program, it act as a shell by using readline extension.

But I find that when I press Ctrl + C, the whole program exits. I hope it can get a new prompt instead of exit (just like bash).

So I try pcntl_signal to handle the SIGINT

pcntl_signal(SIGINT, SIG_IGN);
Run Code Online (Sandbox Code Playgroud)

It doesn't exit and response nothing (just like dead)

I change the code to:

pcntl_signal(SIGINT, function(){
    echo "\n";
});
Run Code Online (Sandbox Code Playgroud)

这次它打印^C但没有新行,当我按下Enter这些时,提示之前是一个新行。 …

php signals readline pcntl

5
推荐指数
0
解决办法
182
查看次数

标签 统计

pcntl ×1

php ×1

readline ×1

signals ×1