改名
This commit is contained in:
@@ -8,16 +8,14 @@ use Database\Connection;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use PHPMailer\PHPMailer\PHPMailer;
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
use PHPMailer\PHPMailer\SMTP;
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
use ReflectionException;
|
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
use Snowflake\Error\Logger;
|
use Snowflake\Core\Json;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
use Snowflake\Exception\ComponentException;
|
use Snowflake\Exception\ComponentException;
|
||||||
use Snowflake\Exception\ConfigException;
|
use Snowflake\Exception\ConfigException;
|
||||||
use Snowflake\Exception\NotFindClassException;
|
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
use Swoole\Coroutine\Server;
|
use Swoole\Process;
|
||||||
use Swoole\Timer;
|
use Swoole\Server;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,14 +32,14 @@ abstract class Callback extends HttpService
|
|||||||
* @param $message
|
* @param $message
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function clear($server, $worker_id, $message)
|
protected function clear(Server $server, $worker_id, $message)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Snowflake::clearProcessId($server->worker_pid);
|
Snowflake::clearProcessId($server->worker_pid);
|
||||||
|
|
||||||
$logger = Snowflake::app()->getLogger();
|
/** @var Process $logger */
|
||||||
$logger->write($this->_MESSAGE[$message] . $worker_id);
|
$logger = Snowflake::app()->get('logger_process');
|
||||||
$logger->clear();
|
$logger->write(Json::encode([$this->_MESSAGE[$message] . $worker_id, 'app']));
|
||||||
|
|
||||||
$this->eventNotify($message);
|
$this->eventNotify($message);
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
@@ -156,7 +154,6 @@ abstract class Callback extends HttpService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
namespace HttpServer;
|
namespace HttpServer;
|
||||||
|
|
||||||
|
use HttpServer\Abstracts\Callback;
|
||||||
use HttpServer\Abstracts\HttpService;
|
use HttpServer\Abstracts\HttpService;
|
||||||
use HttpServer\Events\OnClose;
|
use HttpServer\Events\OnClose;
|
||||||
use HttpServer\Events\OnConnect;
|
use HttpServer\Events\OnConnect;
|
||||||
@@ -69,7 +70,8 @@ class Server extends HttpService
|
|||||||
|
|
||||||
|
|
||||||
private array $process = [
|
private array $process = [
|
||||||
'biomonitoring' => Biomonitoring::class
|
'biomonitoring' => Biomonitoring::class,
|
||||||
|
'logger_process' => Callback::class
|
||||||
];
|
];
|
||||||
|
|
||||||
private array $params = [];
|
private array $params = [];
|
||||||
@@ -99,13 +101,11 @@ class Server extends HttpService
|
|||||||
/**
|
/**
|
||||||
* @param array $configs
|
* @param array $configs
|
||||||
* @return Packet|Websocket|Receive|Http|null
|
* @return Packet|Websocket|Receive|Http|null
|
||||||
* @throws ConfigException
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function initCore(array $configs): Packet|Websocket|Receive|Http|null
|
public function initCore(array $configs): Packet|Websocket|Receive|Http|null
|
||||||
{
|
{
|
||||||
$this->orders($configs);
|
$this->orders($configs);
|
||||||
$this->onProcessListener();
|
|
||||||
return $this->getServer();
|
return $this->getServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,6 +376,8 @@ class Server extends HttpService
|
|||||||
}
|
}
|
||||||
$this->baseServer->set($settings);
|
$this->baseServer->set($settings);
|
||||||
|
|
||||||
|
$this->onProcessListener();
|
||||||
|
|
||||||
return $this->baseServer;
|
return $this->baseServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-11
@@ -160,19 +160,11 @@ class Logger extends Component
|
|||||||
if (empty($messages)) {
|
if (empty($messages)) {
|
||||||
return;
|
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;
|
$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) . '/*');
|
/** @var Process $logger */
|
||||||
if (count($files) >= 15) {
|
$logger = Snowflake::app()->get('logger_process');
|
||||||
$command = 'find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;';
|
$logger->write(Json::encode([$logFile, $method]));
|
||||||
if (Context::inCoroutine())
|
|
||||||
Coroutine\System::exec($command);
|
|
||||||
else
|
|
||||||
\shell_exec($command);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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