server.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 Hyperf\Framework\Bootstrap\PipeMessageCallback;
  12. use Hyperf\Framework\Bootstrap\ServerStartCallback;
  13. use Hyperf\Framework\Bootstrap\WorkerExitCallback;
  14. use Hyperf\Framework\Bootstrap\WorkerStartCallback;
  15. use Hyperf\Server\Event;
  16. use Hyperf\Server\Server;
  17. use Hyperf\Server\ServerInterface;
  18. return [
  19. 'type' => Server::class,
  20. 'mode' => SWOOLE_BASE,
  21. 'servers' => [
  22. [
  23. 'name' => 'http',
  24. 'type' => ServerInterface::SERVER_HTTP,
  25. 'host' => '0.0.0.0',
  26. 'port' => 9501,
  27. 'sock_type' => SWOOLE_SOCK_TCP,
  28. 'callbacks' => [
  29. Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
  30. ],
  31. 'options' => [
  32. // Whether to enable request lifecycle event
  33. 'enable_request_lifecycle' => false,
  34. ],
  35. ],
  36. ],
  37. 'processes' => [
  38. ],
  39. 'settings' => [
  40. 'enable_coroutine' => true,
  41. 'worker_num' => 4,
  42. 'pid_file' => BASE_PATH . '/runtime/hyperf.pid',
  43. 'open_tcp_nodelay' => true,
  44. 'max_coroutine' => 100000,
  45. 'open_http2_protocol' => true,
  46. 'max_request' => 0,
  47. 'socket_buffer_size' => 2 * 1024 * 1024,
  48. ],
  49. 'callbacks' => [
  50. Event::ON_BEFORE_START => [ServerStartCallback::class, 'beforeStart'],
  51. Event::ON_WORKER_START => [WorkerStartCallback::class, 'onWorkerStart'],
  52. Event::ON_PIPE_MESSAGE => [PipeMessageCallback::class, 'onPipeMessage'],
  53. Event::ON_WORKER_EXIT => [WorkerExitCallback::class, 'onWorkerExit'],
  54. ],
  55. ];