swoole-framwork/core/init/TestProcess.php

30 lines
897 B
PHP
Raw Normal View History

2024-05-20 11:51:07 +08:00
<?php
namespace Core\init;
use Swoole\Process;
use Core\helper\FileHelper;
class TestProcess
{
private $md5file;
public function run()
{
$process = new Process(function() {
while (true) {
sleep(3);
$md5Value = FileHelper::getFileMd5(ROOT_PATH.'/app/*','/app/config');
if ($this->md5file==''){
$this->md5file = $md5Value;
continue;
}
if (strcmp($this->md5file,$md5Value)!==0){
echo "代码有改动重新加载ing".PHP_EOL;
$getPid = intval(file_get_contents("./ttt.pid"));
Process::kill($getPid,SIGUSR1);
$this->md5file = $md5Value;
echo "重新加载ed".PHP_EOL;
}
}
});
return $process;
}
}