server.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://doc.hyperf.io
  8. * @contact [email protected]
  9. * @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
  10. */
  11. use Hyperf\Server\Server;
  12. use Hyperf\Server\SwooleEvent;
  13. return [
  14. 'mode' => SWOOLE_BASE,
  15. 'servers' => [
  16. [
  17. 'name' => 'http',
  18. 'type' => Server::SERVER_HTTP,
  19. 'host' => '0.0.0.0',
  20. 'port' => 9501,
  21. 'sock_type' => SWOOLE_SOCK_TCP,
  22. 'callbacks' => [
  23. SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
  24. ],
  25. ],
  26. ],
  27. 'settings' => [
  28. 'enable_coroutine' => true,
  29. 'reactor_num' => swoole_cpu_num() * 2,
  30. 'worker_num' => swoole_cpu_num(),
  31. 'task_worker_num' => swoole_cpu_num(),
  32. 'pid_file' => BASE_PATH . '/runtime/hyperf.pid',
  33. 'open_tcp_nodelay' => true,
  34. 'open_cpu_affinity' => true,
  35. 'max_connection' => 100000,
  36. 'log_level' => SWOOLE_LOG_NONE,
  37. ],
  38. 'callbacks' => [
  39. SwooleEvent::ON_BEFORE_START => [Hyperf\Framework\Bootstrap\ServerStartCallback::class, 'beforeStart'],
  40. SwooleEvent::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
  41. SwooleEvent::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
  42. // Task callbacks
  43. SwooleEvent::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
  44. SwooleEvent::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
  45. ],
  46. ];