<?php
use Workerman\Worker;
use Workerman\Lib\Timer;
$time = time();
$path = APPPATH.'Taskmgr/';
/**
* 检测函数
* @param $monitor_dir
* @param $timerID
*/
function check_files($monitor_dir='',$timerID='')
{
global $time;
$dir_iterator = new RecursiveDirectoryIterator($monitor_dir);
$iterator = new RecursiveIteratorIterator($dir_iterator);
foreach ($iterator as $file)
{
if(pathinfo($file, PATHINFO_EXTENSION) != 'php')
{
continue;
}
if($time < $file->getMTime())
{
posix_kill(posix_getppid(), SIGUSR1);//重载
$time = $file->getMTime();
break;
}
}
test();
}
$worker = new Worker();
$worker->name = 'FileMonitor';
$worker->reloadable = true;
$worker->onWorkerStart = function()
{
global $path;
$time_id = Timer::add(1, 'check_files', array($path,&$time_id));
};
$worker->onWorkerReload = function()
{
test();
};
function test()
{
Worker::$logFile = APPPATH.'log.txt';
$arr = include_once APPPATH.'Taskmgr/List.php';
// Worker::log(var_export($arr,true));
echo "11111331\n";
}
说明下:我这个文件就是在Taskmgr目录下,更改代码后能反映出来文件被更新了,但是就是输出的还是更改之前的东西。
只有在on{...}回调中载入的文件平滑重启后才会自动更新,但是我怎么搞都不会自动更新,愣是没搞明白,请指点下!
另外请教下,本来是想放在CI的控制器里面执行的,结果php index.php task/index/test start 死活执行不了,我看那些thinkphp的代码也是这样执行的,就不明白CI框架怎么就执行不了。
http://wenda.workerman.net/?/question/1135
原来是这么回事。
ok