PHP的守护进程。可以用于列队处理一些需要延迟处理的功能

/**
* Kalon Daemon -> A Unix Daemon for PHP5
* This is a free daemon tool, you can use it anyway you like.
*
* NOTICE:
* 1:This tool must run in cli sapi, any other sapis will cause a
* KalonDaemonException thrown.so you need to use this tool in a
* command line interface,command such as: /path/to/php mydaemon.php
*
* 2:Daemon needs pcntl and posix extension support. Make sure your cli
* sapi has loaded these two extension.The posix is compiled in php by
* default, while pcntl must be compiled or dynamic load by yourself.
* Missing anyone of these extension will cause a KalonDaemonException
* thrown.
*
* USAGE:
*
*put the code below in mydaemon.php
*
require_once '/path/to/KalonDaemon.php';
declare(ticks = 1);
$toDo = $_SERVER['argv'][1];
$daemonConf = array('pidFilePath' => 'mydaemon.pid',
'verbose' => true);
function myHandler1()
{
sleep(5);
echo "This handler1 works./n";
}
function myHandler2()
{
echo "This handler2 works./n";
}
try {
$daemon = new KalonDaemon($daemonConf);
if ($toDo == 'start') {
$daemon->addSignalHandlerFunction(SIGUSR1, 'myHandler1');
$daemon->addSignalHandlerFunction(SIGUSR2, 'myHandler2');
$daemon->start();
for (;;) {
echo "running./n";
sleep(1000);
}
} elseif ($toDo == 'stop') {
$daemon->stop();
} else {
die("unknown action.");
}
} catch (KalonDaemonException $e) {
echo $e->getMessage();
echo "/n";
}
*
* then open a command shell:
* start daemon:
* /path/to/phpcli/php /path/to/mydaemon.php start
*
* stop daemon:
* /path/to/phpcli/php /path/to/mydaemon.php stop
*
*
*
* @author 玉面修罗 - Kalon
* @version 1.0
* @site: www.phpthink.com
* E-mail/MSN: xiuluo-999@163.com
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值