server.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Server\Event;
  12. use Hyperf\Server\Server;
  13. use Swoole\Constant;
  14. return [
  15. 'mode' => SWOOLE_PROCESS,
  16. 'servers' => [
  17. [
  18. 'name' => 'http',
  19. 'type' => Server::SERVER_HTTP,
  20. 'host' => '0.0.0.0',
  21. 'port' => 9501,
  22. 'sock_type' => SWOOLE_SOCK_TCP,
  23. 'callbacks' => [
  24. Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
  25. ],
  26. ],
  27. [
  28. 'name' => 'ws',
  29. 'type' => Server::SERVER_WEBSOCKET,
  30. 'host' => '0.0.0.0',
  31. 'port' => 9506,
  32. 'sock_type' => SWOOLE_SOCK_TCP,
  33. 'callbacks' => [
  34. Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
  35. Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
  36. Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
  37. ],
  38. ],
  39. ],
  40. 'settings' => [
  41. 'document_root' => BASE_PATH . '/public',
  42. 'enable_static_handler' => true,
  43. Constant::OPTION_ENABLE_COROUTINE => true,
  44. Constant::OPTION_WORKER_NUM => swoole_cpu_num(),
  45. Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',
  46. Constant::OPTION_OPEN_TCP_NODELAY => true,
  47. Constant::OPTION_MAX_COROUTINE => 100000,
  48. Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
  49. Constant::OPTION_MAX_REQUEST => 100000,
  50. Constant::OPTION_SOCKET_BUFFER_SIZE => 2 * 1024 * 1024,
  51. Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
  52. ],
  53. 'callbacks' => [
  54. Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
  55. Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
  56. Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
  57. ],
  58. ];