Skip to content

Commit

Permalink
Update windows.php
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor authored Aug 15, 2022
1 parent cf61730 commit d05043d
Showing 1 changed file with 30 additions and 42 deletions.
72 changes: 30 additions & 42 deletions windows.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/
require_once __DIR__ . '/vendor/autoload.php';

use Dotenv\Dotenv;
use process\Monitor;
use support\App;
use Dotenv\Dotenv;
use Workerman\Worker;
use Webman\Config;

ini_set('display_errors', 'on');
error_reporting(E_ALL);
Expand All @@ -20,7 +20,7 @@
}
}

Config::load(config_path(), ['route', 'container']);
App::loadAllConfig(['route']);

$error_reporting = config('app.error_reporting');
if (isset($error_reporting)) {
Expand All @@ -35,46 +35,34 @@
__DIR__ . DIRECTORY_SEPARATOR . 'start.php'
];
foreach (config('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('$process_name', config('process')['$process_name']);
if (DIRECTORY_SEPARATOR != "/") {
Worker::\$logFile = config('server')['log_file'] ?? Worker::\$logFile;
}
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);
$process_files[] = write_process_file($runtime_process_path, $process_name, '');
}

foreach (config('plugin', []) as $firm => $projects) {
foreach ($projects as $name => $project) {
if (!is_array($project)) {
continue;
}
foreach ($project['process'] ?? [] as $process_name => $config) {
$file_content = <<<EOF
$process_files[] = write_process_file($runtime_process_path, $process_name, "$firm.$name");
}
}
foreach ($projects['process'] ?? [] as $process_name => $config) {
$process_files[] = write_process_file($runtime_process_path, $process_name, $firm);
}
}

function write_process_file($runtime_process_path, $process_name, $firm)
{
$process_param = $firm ? "plugin.$firm.$process_name" : $process_name;
$config_param = $firm ? "config('plugin.$firm.process')['$process_name']" : "config('process')['$process_name']";
$file_content = <<<EOF
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use Workerman\Worker;
use Webman\Config;
use support\App;
ini_set('display_errors', 'on');
error_reporting(E_ALL);
Expand All @@ -83,9 +71,9 @@
opcache_reset();
}
Config::load(config_path(), ['route', 'container']);
App::loadAllConfig(['route']);
worker_start("plugin.$firm.$name.$process_name", config("plugin.$firm.$name.process")['$process_name']);
worker_start('$process_param', $config_param);
if (DIRECTORY_SEPARATOR != "/") {
Worker::\$logFile = config('server')['log_file'] ?? Worker::\$logFile;
Expand All @@ -94,14 +82,14 @@
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);
}
}
$process_file = $runtime_process_path . DIRECTORY_SEPARATOR . "start_$process_param.php";
file_put_contents($process_file, $file_content);
return $process_file;
}

$monitor = new Monitor(...array_values(config('process.monitor.constructor')));
if ($monitor_config = config('process.monitor.constructor')) {
$monitor = new Monitor(...array_values($monitor_config));
}

function popen_processes($process_files)
{
Expand All @@ -118,7 +106,7 @@ function popen_processes($process_files)
echo "\r\n";
while (1) {
sleep(1);
if ($monitor->checkAllFilesChange()) {
if (!empty($monitor) && $monitor->checkAllFilesChange()) {
$status = proc_get_status($resource);
$pid = $status['pid'];
shell_exec("taskkill /F /T /PID $pid");
Expand Down

0 comments on commit d05043d

Please sign in to comment.