Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ebcb7237ef | |||
| 5c1282959c | |||
| 115273e5a4 | |||
| 709f2e273e | |||
| 536e4c9bc5 | |||
| 91be2eba20 | |||
| d7f5f62c1c | |||
| 8b8bfa2a60 | |||
| 1ecf32bfa6 | |||
| 8c0c5b56c8 |
+3
-8
@@ -23,7 +23,7 @@
|
||||
"ext-openssl": "*",
|
||||
"ext-swoole": "*",
|
||||
"ext-msgpack": "*",
|
||||
"symfony/console": "^v8.0",
|
||||
"symfony/console": "^v8.1.1",
|
||||
"psr/log": "1.*",
|
||||
"composer-runtime-api": "^2.0",
|
||||
"psr/http-server-middleware": "^1.0.2",
|
||||
@@ -32,17 +32,12 @@
|
||||
"nikic/php-parser": "^v5.5.0",
|
||||
"ext-inotify": "*",
|
||||
"game-worker/kiri-pool": "^v1.0",
|
||||
"psr/container": "^2.0",
|
||||
"swiftmailer/swiftmailer": "^v6.3.0"
|
||||
"psr/container": "^2.0"
|
||||
},
|
||||
"replace": {
|
||||
"symfony/polyfill-apcu": "*",
|
||||
"symfony/polyfill-php80": "*",
|
||||
"symfony/polyfill-mbstring": "*",
|
||||
"symfony/polyfill-ctype": "*",
|
||||
"symfony/polyfill-php73": "*",
|
||||
"symfony/polyfill-php72": "*",
|
||||
"symfony/polyfill-php81": "*"
|
||||
"symfony/polyfill-ctype": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
+19
-14
@@ -166,8 +166,7 @@ if (!function_exists('isJson')) {
|
||||
{
|
||||
if (is_null($string))
|
||||
return false;
|
||||
return (str_starts_with($string, '{') && str_ends_with($string, '}'))
|
||||
|| (str_ends_with($string, '[') && str_starts_with($string, ']'));
|
||||
return (str_starts_with($string, '{') && str_ends_with($string, '}')) || (str_ends_with($string, '[') && str_starts_with($string, ']'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -219,33 +218,41 @@ if (!function_exists('checkPortIsAlready')) {
|
||||
/**
|
||||
* @param $port
|
||||
* @return bool|string
|
||||
* @throws
|
||||
*/
|
||||
function checkPortIsAlready($port): bool|string
|
||||
{
|
||||
$port = (int)$port;
|
||||
if ($port <= 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!Kiri::getPlatform()->isLinux()) {
|
||||
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
|
||||
if (empty($output))
|
||||
if (empty($output)) {
|
||||
return FALSE;
|
||||
}
|
||||
$output = explode(PHP_EOL, $output[0]);
|
||||
return $output[0];
|
||||
}
|
||||
|
||||
$serverPid = file_get_contents(storage('.swoole.pid'));
|
||||
if (!empty($serverPid) && shell_exec('ps -ef | grep ' . $serverPid . ' | grep -v grep')) {
|
||||
Process::kill($serverPid, 0) && Process::kill($serverPid, SIGTERM);
|
||||
exec('netstat -lnp 2>/dev/null | grep :' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
|
||||
if (empty($output)) {
|
||||
exec('ss -ltnp 2>/dev/null | grep :' . $port . ' | sed -n \"s/.*pid=\\([0-9]*\\).*/\\1/p\"', $output);
|
||||
}
|
||||
|
||||
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
|
||||
if (empty($output)) {
|
||||
return FALSE;
|
||||
}
|
||||
return explode('/', $output[0])[0];
|
||||
|
||||
$pid = trim((string)$output[0]);
|
||||
if (str_contains($pid, '/')) {
|
||||
$pid = explode('/', $pid)[0];
|
||||
}
|
||||
|
||||
return $pid !== '' ? $pid : FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('set_env')) {
|
||||
|
||||
|
||||
@@ -1029,9 +1036,7 @@ if (!function_exists('json_log')) {
|
||||
];
|
||||
$param['data'] = $data;
|
||||
|
||||
file_put_contents(storage('exception-' . date('Y-m-d') . '.log','exception'),
|
||||
json_encode($param, JSON_UNESCAPED_UNICODE),
|
||||
FILE_APPEND);
|
||||
file_put_contents(storage('exception-' . date('Y-m-d') . '.log', 'exception'), json_encode($param, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ use Symfony\Component\Console\{Application as ConsoleApplication,
|
||||
Output\OutputInterface
|
||||
};
|
||||
use Kiri\Server\ServerCommand;
|
||||
use Kiri\Server\FileBuildCommand;
|
||||
use Kiri\Di\Inject\Container;
|
||||
use function config;
|
||||
|
||||
@@ -73,10 +74,14 @@ class Application extends BaseApplication
|
||||
*/
|
||||
public function beforeCommandExecute(OnBeforeCommandExecute $beforeCommandExecute): void
|
||||
{
|
||||
if ($beforeCommandExecute->command instanceof ServerCommand) {
|
||||
if ($beforeCommandExecute->command instanceof ServerCommand || $beforeCommandExecute->command instanceof FileBuildCommand) {
|
||||
return;
|
||||
}
|
||||
$scanner = $this->container->get(Scanner::class);
|
||||
$scanner->setConfig(array_merge(
|
||||
config('servers.reload.scan', []),
|
||||
config('site.scanner', [])
|
||||
));
|
||||
$scanner->scan(APP_PATH . 'app/');
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class Coordinator
|
||||
|
||||
const string WORKER_START = 'worker:start';
|
||||
|
||||
private bool $wait = true;
|
||||
private bool $wait = false;
|
||||
|
||||
private ?Channel $channel = null;
|
||||
|
||||
@@ -22,12 +22,17 @@ class Coordinator
|
||||
public function yield(): void
|
||||
{
|
||||
if (Coroutine::getCid() > 0) {
|
||||
$this->channel = new Channel(1);
|
||||
if ($this->channel instanceof Channel) {
|
||||
$this->channel->pop();
|
||||
} else {
|
||||
while ($this->wait) {
|
||||
usleep(1000);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->wait === false) {
|
||||
return;
|
||||
}
|
||||
while ($this->wait === true) {
|
||||
usleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +42,7 @@ class Coordinator
|
||||
*/
|
||||
public function wait(): void
|
||||
{
|
||||
$this->wait = true;
|
||||
$this->channel = null;
|
||||
Coroutine::getCid() > 0 ? $this->channel = new Channel(1) : $this->wait = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +51,13 @@ class Coordinator
|
||||
*/
|
||||
public function done(): void
|
||||
{
|
||||
$this->wait = false;
|
||||
if (Coroutine::getCid() > 0) {
|
||||
$this->channel?->push(true);
|
||||
$this->channel->close();
|
||||
$this->channel = null;
|
||||
} else {
|
||||
$this->wait = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Kiri\Error;
|
||||
use Closure;
|
||||
use ErrorException;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Di\Scanner;
|
||||
use Kiri\Events\OnSystemError;
|
||||
use Throwable;
|
||||
|
||||
@@ -85,16 +86,23 @@ class ErrorHandler extends Component implements ErrorInterface
|
||||
public function shutdown(): void
|
||||
{
|
||||
$lastError = error_get_last();
|
||||
if (empty($lastError) || $lastError['type'] !== E_ERROR) {
|
||||
$fatalTypes = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR];
|
||||
if (empty($lastError) || !in_array($lastError['type'], $fatalTypes, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (class_exists(Scanner::class, false)) {
|
||||
$scanFile = Scanner::getCurrentFile();
|
||||
if ($scanFile !== null) {
|
||||
$lastError['scanner_file'] = $scanFile;
|
||||
}
|
||||
}
|
||||
|
||||
$this->getLogger()->println(json_encode($lastError, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
event(new OnSystemError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Throwable $exception
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user