分享一个php处理信号的小例子
时间:2021-12-03
来源:互联网
今天PHP爱好者为您带来我们常用的信号:kill sigterm sigkill【kill命令】;ctrl+c sigint【键盘发出】;reload sinhub【一般从终端发出】;ctrl+z sigstop 【键盘发出】...希望对大家有所帮助。
php 处理信号简单演示
我们常用的信号
kill sigterm sigkill
ctrl+c sigint
reload sinhub
ctrl+z sigstop
定时器 sigalarm
sigkill和sinstop 在进行信号处理时,不能被忽略,(处理信号可以有忽略,执行默认 执行用户指定处理)
php信号小例子
<?php
function sighandler($signo){
echo 'just for sigint',"\n";
}
function sighandler2($signo){
echo 'just for sigquit',"\n";
}
declare(ticks=1);
pcntl_signal(SIGINT,"sighandler");
pcntl_signal(SIGQUIT,"sighandler2");
for($i=1;$i<30;$i++){
file_put_contents('/home/tbtest/out.txt',"$i"."秒\n");
sleep(1);
}
~
执行结果
root@lyh:/home/tbtest# php sigint.php
^Cjust for sigint
^Cjust for sigint
^Cjust for sigint
just for sigquit
^Cjust for sigint
^Cjust for sigint
^Z
[1]+ Stopped php sigint.php
root@lyh:/home/tbtest# bg
[1]+ php sigint.php &
root@lyh:/home/tbtest# fg
php sigint.php
root@lyh:/home/tbtest# cat out.txt
29秒
root@lyh:/home/tbtest#
关于捕捉sigquit
上面捕捉到了jsut for sigquit 是因为我另外起了一个终端,
root@lyh:~# ps -aux |grep php
root 16385 0.5 1.9 377720 19468 pts/2 S+ 15:09 0:00 php sigint.php
root 16390 0.0 0.0 11744 932 pts/0 S+ 15:09 0:00 grep --color=auto php
root@lyh:~# kill -s sigquit 16385
ps:pcntl_signal_dispatch 比ticks效率会更高
以上就是分享一个php处理信号的小例子的详细内容,更多请关注php爱好者其它相关文章!
-
币安交易所安全提示合集 时间:2025-05-12
-
币安交易所如何识别官方渠道 时间:2025-05-12
-
币安交易所用户隐私政策 时间:2025-05-12
-
币安交易所如何设置登录保护 时间:2025-05-12
-
币安交易所安全认证流程 时间:2025-05-12
-
Linux中export命令详解(定义、基本用法、高级用法、应用场景等) 时间:2025-05-12
今日更新
-
react怎么实现文件转base64
阅读:18
-
linux ubuntu怎么安装mysql
阅读:18
-
mysql 怎么查询月份
阅读:18
-
css怎样给按钮设置背景图片
阅读:18
-
git和svn有哪些区别
阅读:18
-
mysql or用法是什么
阅读:18
-
教你在Phpstorm中快速批量删除空行
阅读:18
-
什么是javascript算术运算符
阅读:18
-
Javascript中什么是数组
阅读:18
-
css3怎么改变字体
阅读:18