This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Command processes `swoole:server:run` and `swoole:server:profile` killed with SIGINT (CONTROL-C), previously were killed not gracefully (event console.terminate) was not emitted.
- Loading branch information
Showing
5 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Configurator; | ||
|
||
use K911\Swoole\Server\LifecycleHandler\ServerStartHandlerInterface; | ||
use Swoole\Http\Server; | ||
|
||
final class WithServerStartHandler implements ConfiguratorInterface | ||
{ | ||
private $handler; | ||
private $decorated; | ||
|
||
public function __construct(ConfiguratorInterface $decorated, ServerStartHandlerInterface $handler) | ||
{ | ||
$this->handler = $handler; | ||
$this->decorated = $decorated; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configure(Server $server): void | ||
{ | ||
$this->decorated->configure($server); | ||
|
||
$server->on('start', [$this->handler, 'handle']); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Server/LifecycleHandler/ServerStartHandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Server; | ||
|
||
interface ServerStartHandlerInterface | ||
{ | ||
/** | ||
* Handle "OnStart" event. | ||
* | ||
* @param Server $server | ||
*/ | ||
public function handle(Server $server): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\LifecycleHandler; | ||
|
||
use Swoole\Process; | ||
use Swoole\Server; | ||
|
||
final class SigIntHandler implements ServerStartHandlerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Server $server): void | ||
{ | ||
// 2 => SIGINT | ||
Process::signal(2, [$server, 'shutdown']); | ||
} | ||
} |