改名
This commit is contained in:
@@ -8,16 +8,14 @@ use Database\Connection;
|
||||
use Exception;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use ReflectionException;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Error\Logger;
|
||||
use Snowflake\Core\Json;
|
||||
use Snowflake\Event;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Coroutine\Server;
|
||||
use Swoole\Timer;
|
||||
use Swoole\Process;
|
||||
use Swoole\Server;
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,14 +32,14 @@ abstract class Callback extends HttpService
|
||||
* @param $message
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function clear($server, $worker_id, $message)
|
||||
protected function clear(Server $server, $worker_id, $message)
|
||||
{
|
||||
try {
|
||||
Snowflake::clearProcessId($server->worker_pid);
|
||||
|
||||
$logger = Snowflake::app()->getLogger();
|
||||
$logger->write($this->_MESSAGE[$message] . $worker_id);
|
||||
$logger->clear();
|
||||
/** @var Process $logger */
|
||||
$logger = Snowflake::app()->get('logger_process');
|
||||
$logger->write(Json::encode([$this->_MESSAGE[$message] . $worker_id, 'app']));
|
||||
|
||||
$this->eventNotify($message);
|
||||
} catch (\Throwable $exception) {
|
||||
@@ -156,7 +154,6 @@ abstract class Callback extends HttpService
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @throws ConfigException
|
||||
* @throws ComponentException
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
namespace HttpServer;
|
||||
|
||||
use HttpServer\Abstracts\Callback;
|
||||
use HttpServer\Abstracts\HttpService;
|
||||
use HttpServer\Events\OnClose;
|
||||
use HttpServer\Events\OnConnect;
|
||||
@@ -69,7 +70,8 @@ class Server extends HttpService
|
||||
|
||||
|
||||
private array $process = [
|
||||
'biomonitoring' => Biomonitoring::class
|
||||
'biomonitoring' => Biomonitoring::class,
|
||||
'logger_process' => Callback::class
|
||||
];
|
||||
|
||||
private array $params = [];
|
||||
@@ -99,13 +101,11 @@ class Server extends HttpService
|
||||
/**
|
||||
* @param array $configs
|
||||
* @return Packet|Websocket|Receive|Http|null
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function initCore(array $configs): Packet|Websocket|Receive|Http|null
|
||||
{
|
||||
$this->orders($configs);
|
||||
$this->onProcessListener();
|
||||
return $this->getServer();
|
||||
}
|
||||
|
||||
@@ -376,6 +376,8 @@ class Server extends HttpService
|
||||
}
|
||||
$this->baseServer->set($settings);
|
||||
|
||||
$this->onProcessListener();
|
||||
|
||||
return $this->baseServer;
|
||||
}
|
||||
|
||||
|
||||
+3
-11
@@ -160,19 +160,11 @@ class Logger extends Component
|
||||
if (empty($messages)) {
|
||||
return;
|
||||
}
|
||||
$fileName = 'server-' . date('Y-m-d') . '.log';
|
||||
$dirName = 'log/' . (empty($method) ? 'app' : $method);
|
||||
$logFile = '[' . date('Y-m-d H:i:s') . ']:' . PHP_EOL . $messages . PHP_EOL;
|
||||
Snowflake::writeFile(storage($fileName, $dirName), $logFile, FILE_APPEND);
|
||||
|
||||
$files = glob(storage(null, $dirName) . '/*');
|
||||
if (count($files) >= 15) {
|
||||
$command = 'find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;';
|
||||
if (Context::inCoroutine())
|
||||
Coroutine\System::exec($command);
|
||||
else
|
||||
\shell_exec($command);
|
||||
}
|
||||
/** @var Process $logger */
|
||||
$logger = Snowflake::app()->get('logger_process');
|
||||
$logger->write(Json::encode([$logFile, $method]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Snowflake\Error;
|
||||
|
||||
|
||||
use HttpServer\Http\Context;
|
||||
use Snowflake\Core\Json;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Process\Process;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Coroutine;
|
||||
|
||||
|
||||
/**
|
||||
* Class LoggerProcess
|
||||
* @package Snowflake\Error
|
||||
*/
|
||||
class LoggerProcess extends Process
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
* @throws ComponentException
|
||||
*/
|
||||
public function onHandler(\Swoole\Process $process): void
|
||||
{
|
||||
// TODO: Implement onHandler() method.
|
||||
|
||||
$this->message($process);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
* @throws ComponentException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function message(\Swoole\Process $process)
|
||||
{
|
||||
$message = Json::decode($process->read());
|
||||
if (!empty($message)) {
|
||||
$fileName = 'server-' . date('Y-m-d') . '.log';
|
||||
$dirName = 'log/' . (empty($method) ? 'app' : $method);
|
||||
|
||||
Snowflake::writeFile(storage($fileName, $dirName), $message[0], FILE_APPEND);
|
||||
|
||||
$files = new \DirectoryIterator(storage(null, $dirName) . '/*.log');
|
||||
if ($files->getSize() >= 15) {
|
||||
$command = 'find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;';
|
||||
if (Context::inCoroutine())
|
||||
Coroutine\System::exec($command);
|
||||
else
|
||||
\shell_exec($command);
|
||||
}
|
||||
}
|
||||
|
||||
Coroutine\System::sleep(1);
|
||||
|
||||
$this->message($process);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user