加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
window.php 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
琴歌剑舞 提交于 2024-11-21 12:10 . feat: 调整部分方法
<?php
$base_dir = __DIR__;
$think = $base_dir . DIRECTORY_SEPARATOR . 'think';
$cmd = $base_cmd = PHP_BINARY . ' ' . $think . ' workerman start -s httpServer';
$descriptorspec = [STDIN, STDOUT, STDOUT];
$resource = proc_open($cmd, $descriptorspec, $pipes, null, null, ['bypass_shell' => true]);
if (!$resource) {
exit("Can not execute $cmd\r\n");
}
// 监听的文件目录
$paths = [
$base_dir . DIRECTORY_SEPARATOR . '/app/',
$base_dir . DIRECTORY_SEPARATOR . '/config/',
$base_dir . DIRECTORY_SEPARATOR . '/fast/',
];
$files = [
$base_dir . DIRECTORY_SEPARATOR . '/.env',
];
// 当前启动的时间
$lastMtime = time();
while (1) {
sleep(2);
foreach($files as $file) {
$info = new SplFileInfo($file);
if ($lastMtime < $info->getMTime()) {
$lastMtime = $info->getMTime();
$status = proc_get_status($resource);
$pid = $status['pid'];
shell_exec("taskkill /F /T /PID $pid");
$resource = proc_open($cmd, $descriptorspec, $pipes, null, null, ['bypass_shell' => true]);;
break;
}
}
foreach ($paths as $path) {
$dir = new RecursiveDirectoryIterator($path);
$iterator = new RecursiveIteratorIterator($dir);
foreach ($iterator as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) != 'php') {
continue;
}
// 文件的修改时间
if ($lastMtime < $file->getMTime()) {
echo '[update]' . $file . "\n";
$lastMtime = $file->getMTime();
$status = proc_get_status($resource);
$pid = $status['pid'];
shell_exec("taskkill /F /T /PID $pid");
$resource = proc_open($cmd, $descriptorspec, $pipes, null, null, ['bypass_shell' => true]);;
break 2;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化