SrandStartHandler.php 625 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Swoole;
  3. use K911\Swoole\Server\WorkerHandler\WorkerStartHandlerInterface;
  4. use Swoole\Http\Request;
  5. use Swoole\Http\Response;
  6. use Swoole\Server;
  7. final class SrandStartHandler implements WorkerStartHandlerInterface
  8. {
  9. private $decorated;
  10. public function __construct(?WorkerStartHandlerInterface $decorated)
  11. {
  12. $this->decorated = $decorated;
  13. }
  14. public function handle(Server $worker, int $workerId): void
  15. {
  16. if ($this->decorated) {
  17. $this->decorated->handle($worker, $workerId);
  18. }
  19. // Seed the random generator
  20. \mt_srand();
  21. }
  22. }