server.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. use function Hyperf\Support\env;
  12. use Hyperf\Server\Event;
  13. use Hyperf\Server\Server;
  14. use Swoole\Constant;
  15. return [
  16. 'mode' => SWOOLE_PROCESS,
  17. 'servers' => [
  18. [
  19. 'name' => 'http',
  20. 'type' => Server::SERVER_HTTP,
  21. 'host' => (string) env('HTTP_HOST', '0.0.0.0'),
  22. 'port' => (int) env('HTTP_PORT', 9501),
  23. 'sock_type' => SWOOLE_SOCK_TCP,
  24. 'callbacks' => [
  25. Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
  26. ],
  27. 'options' => [
  28. // Whether to enable request lifecycle event
  29. 'enable_request_lifecycle' => false,
  30. ],
  31. ],
  32. ],
  33. 'settings' => [
  34. Constant::OPTION_ENABLE_COROUTINE => true,
  35. Constant::OPTION_WORKER_NUM => swoole_cpu_num(),
  36. Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',
  37. Constant::OPTION_OPEN_TCP_NODELAY => true,
  38. Constant::OPTION_MAX_COROUTINE => 100000,
  39. Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
  40. Constant::OPTION_MAX_REQUEST => 100000,
  41. Constant::OPTION_SOCKET_BUFFER_SIZE => 2 * 1024 * 1024,
  42. Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
  43. ],
  44. 'callbacks' => [
  45. Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
  46. Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
  47. Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
  48. ],
  49. ];