php 创建守护进程
2016-03-03 16:35
731 查看
<?php function signalHandler($signal) { global $worker_pid; if ($signal == SIGINT) { exec("rm -rf ".$worker_pid.'_start_id.pid',$worker_pid); exit(0); } if ($signal == SIGTERM) { exec("rm -rf ".$worker_pid.'_start_id.pid',$worker_pid); exit(0); } } $pid = pcntl_fork(); if ( $pid < 0) { die('fork failed'); } else if ( $pid > 0 ) { exit(0); } //在子进程注册信号 pcntl_signal(SIGINT, 'signalHandler'); pcntl_signal(SIGTERM, 'signalHandler'); $worker_pid = posix_getpid(); if ($worker_pid){ file_put_contents($worker_pid.'_start_id.pid',$worker_pid); } while (1) { //file_put_contents('data.txt',"write name:peen\n",FILE_APPEND); file_get_contents("http://10.150.1.144/Api/Version2_0/VerfiyCode/sendSms"); //每1秒请求一次url sleep(1); pcntl_signal_dispatch(); }
相关文章推荐
- phpstorm10.0.3破解版安装教程及汉化方法 .
- php设计模式 原型模式
- php连接mysql类PDO从php5才开始有
- PHP SESSION 机制
- PHP相关知识了解
- php curl函数请求链接获得结果
- php架构-ThinkPHP架构(一)-TP原理及路径问题及后台实现实例(可运行)
- 将PHP程序中返回的JSON格式数据用gzip压缩输出的方法
- 详解PHP spl_autoload_register()函数
- PHP 正则表达式
- PHP的常用字符串处理
- PHP对观察者模式的支持
- php 正则表达式
- thinkphp 设置404页面
- PHP的数组中提高元素查找与元素去重的效率的技巧解析
- 读《深入php面向对象、模式与实践》有感(二)
- 读《深入php面向对象、模式与实践》有感(二)
- FTP库BlackRaccoon问题解决方案
- PHP判断数组内容是否都为一样的值
- <php>删除(有内容的)文件夹函数程序