<?php
use Workerman\Worker;
use Workerman\Lib\Timer;
$time = time();
$path = APPPATH.'Taskmgr/';
/**
* 檢測函數(shù)
* @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{...}回調(diào)中載入的文件平滑重啟后才會自動更新,但是我怎么搞都不會自動更新,愣是沒搞明白,請指點下!
另外請教下,本來是想放在CI的控制器里面執(zhí)行的,結(jié)果php index.php task/index/test start 死活執(zhí)行不了,我看那些thinkphp的代碼也是這樣執(zhí)行的,就不明白CI框架怎么就執(zhí)行不了。