1 Star 1 Fork 15

saku87/YiAdmin零依后台管理系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
win.php 3.09 KB
一键复制 编辑 原始数据 按行查看 历史
YiAdmin 提交于 2022-04-24 13:51 . init
<?php
/**
* Start file for windows
*/
require_once __DIR__ . '/vendor/autoload.php';
use process\Monitor;
use Workerman\Worker;
use Webman\Config;
ini_set('display_errors', 'on');
error_reporting(E_ALL);
Config::load(config_path(), ['route', 'container']);
$runtime_process_path = runtime_path() . DIRECTORY_SEPARATOR . '/windows';
if (!is_dir($runtime_process_path)) {
mkdir($runtime_process_path);
}
$process_files = [
__DIR__ . DIRECTORY_SEPARATOR . 'start.php'
];
$env = $argv[1] ?? 'pro';
foreach (config('process', []) as $process_name => $config) {
if ((empty($config['env']) || $env != $config['env']) && empty($config['enable'])) continue;
$file_content = <<<EOF
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use Workerman\Worker;
use Webman\Config;
ini_set('display_errors', 'on');
error_reporting(E_ALL);
if (is_callable('opcache_reset')) {
opcache_reset();
}
Config::load(config_path(), ['route', 'container']);
worker_start('$process_name', config('process')['$process_name']);
Worker::runAll();
EOF;
$process_file = $runtime_process_path . DIRECTORY_SEPARATOR . "start_$process_name.php";
$process_files[] = $process_file;
file_put_contents($process_file, $file_content);
}
foreach (config('plugin', []) as $firm => $projects) {
foreach ($projects as $name => $project) {
foreach ($project['process'] ?? [] as $process_name => $config) {
$file_content = <<<EOF
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use Workerman\Worker;
use Webman\Config;
ini_set('display_errors', 'on');
error_reporting(E_ALL);
if (is_callable('opcache_reset')) {
opcache_reset();
}
Config::load(config_path(), ['route', 'container']);
worker_start("plugin.$firm.$name.$process_name", config("plugin.$firm.$name.process")['$process_name']);
Worker::runAll();
EOF;
$process_file = $runtime_process_path . DIRECTORY_SEPARATOR . "start_$process_name.php";
$process_files[] = $process_file;
file_put_contents($process_file, $file_content);
}
}
}
function popen_processes($process_files)
{
$cmd = "php " . implode(' ', $process_files);
$descriptorspec = [STDIN, STDOUT, STDOUT];
$resource = proc_open($cmd, $descriptorspec, $pipes);
if (!$resource) {
exit("Can not execute $cmd\r\n");
}
return $resource;
}
$monitor = new Monitor(...array_values(config('process.monitor.constructor')));
$resource = popen_processes($process_files);
function g_system_reload(&$resource, $process_files)
{
echo "system reloading... \n";
$status = proc_get_status($resource);
$pid = $status['pid'];
shell_exec("taskkill /F /T /PID $pid");
proc_close($resource);
$resource = popen_processes($process_files);
}
echo "\r\n";
while (1) {
sleep(1);
if (trim(file_get_contents(runtime_path() . '\\' . 'signal') == 'WAITING')) {
file_put_contents(runtime_path() . '\\' . 'signal', 'LOADING');
g_system_reload($resource, $process_files);
}
if ($env == 'dev' && $monitor->checkAllFilesChange()) {
g_system_reload($resource, $process_files);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/saku/YiAdmin-Webman.git
git@gitee.com:saku/YiAdmin-Webman.git
saku
YiAdmin-Webman
YiAdmin零依后台管理系统
master

搜索帮助