Logging updates, some function optimisation
This commit is contained in:
@@ -12,6 +12,8 @@ use App\Models\Setup;
|
||||
|
||||
class StartServer extends Command
|
||||
{
|
||||
private const LOGKEY = 'CSS';
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
@@ -26,6 +28,13 @@ class StartServer extends Command
|
||||
*/
|
||||
protected $description = 'Start Server';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
Log::info(sprintf('%s:+ Server Starting (%d)',self::LOGKEY,getmypid()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@@ -54,17 +63,17 @@ class StartServer extends Command
|
||||
|
||||
$children = collect();
|
||||
|
||||
Log::debug(sprintf('%s:+ Starting Servers...',__METHOD__));
|
||||
Log::debug(sprintf('%s: # Servers [%d]',self::LOGKEY,$start->count()));
|
||||
|
||||
if (! $start->count()) {
|
||||
Log::alert(sprintf('%s: - No servers configured to start',__METHOD__));
|
||||
Log::alert(sprintf('%s:- No servers configured to start',self::LOGKEY));
|
||||
return;
|
||||
}
|
||||
|
||||
pcntl_signal(SIGCHLD,SIG_IGN);
|
||||
|
||||
foreach ($start->toArray() as $item => $config) {
|
||||
Log::debug(sprintf('%s: - Starting: [%s]',__METHOD__,$item));
|
||||
foreach ($start as $item => $config) {
|
||||
Log::debug(sprintf('%s: - Starting [%s] (%d)',self::LOGKEY,$item,getmypid()));
|
||||
|
||||
$pid = pcntl_fork();
|
||||
|
||||
@@ -73,7 +82,8 @@ class StartServer extends Command
|
||||
|
||||
// We are the child
|
||||
if (! $pid) {
|
||||
Log::info(sprintf('%s: - Started: [%s]',__METHOD__,$item));
|
||||
Log::withContext(['pid'=>getmypid()]);
|
||||
Log::info(sprintf('%s: - Started [%s]',self::LOGKEY,$item));
|
||||
|
||||
$server = new SocketServer($config['port'],$config['address']);
|
||||
$server->setConnectionHandler([$config['class'],'onConnect']);
|
||||
@@ -83,17 +93,18 @@ class StartServer extends Command
|
||||
|
||||
} catch (SocketException $e) {
|
||||
if ($e->getMessage() == 'Can\'t accept connections: "Success"')
|
||||
Log::debug('Server Terminated');
|
||||
Log::debug(sprintf('%s:! Server Terminated [%s]',self::LOGKEY,$item));
|
||||
else
|
||||
Log::emergency('Uncaught Message: '.$e->getMessage());
|
||||
Log::emergency(sprintf('%s:! Uncaught Message: %s',self::LOGKEY,$e->getMessage()));
|
||||
}
|
||||
|
||||
Log::info(sprintf('%s: - Finished: [%s]',__METHOD__,$item));
|
||||
Log::info(sprintf('%s: - Finished: [%s]',self::LOGKEY,$item));
|
||||
|
||||
// Child finished we need to get out of this loop.
|
||||
exit;
|
||||
}
|
||||
|
||||
Log::info(sprintf('%s: - Forked for [%s] (%d)',self::LOGKEY,$item,$pid));
|
||||
$children->put($pid,$item);
|
||||
}
|
||||
|
||||
@@ -105,10 +116,10 @@ class StartServer extends Command
|
||||
if ($exited < 0)
|
||||
abort(500,'Something strange for status: '.serialize($status));
|
||||
|
||||
Log::info(sprintf('%s: - Exited: #%d [%s]',__METHOD__,$x,$children->pull($exited)));
|
||||
Log::info(sprintf('%s: - Exited: #%d [%s]',self::LOGKEY,$x,$children->pull($exited)));
|
||||
}
|
||||
|
||||
// Done
|
||||
Log::debug(sprintf('%s: = Finished.',__METHOD__));
|
||||
Log::debug(sprintf('%s:= Finished.',self::LOGKEY));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user