server.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 => [App\Service\Server\StreamServer::class, 'onRequest'],
  25. // Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
  26. ],
  27. ],
  28. [
  29. 'name' => 'ws',
  30. 'type' => Server::SERVER_WEBSOCKET,
  31. 'host' => '0.0.0.0',
  32. 'port' => 9506,
  33. 'sock_type' => SWOOLE_SOCK_TCP,
  34. 'callbacks' => [
  35. Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
  36. Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
  37. Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
  38. ],
  39. ],
  40. ],
  41. 'settings' => [
  42. 'document_root' => BASE_PATH . '/public',
  43. 'enable_static_handler' => true,
  44. Constant::OPTION_ENABLE_COROUTINE => true,
  45. Constant::OPTION_WORKER_NUM => swoole_cpu_num(),
  46. Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',
  47. Constant::OPTION_OPEN_TCP_NODELAY => true,
  48. Constant::OPTION_MAX_COROUTINE => 10 * 1024 * 1024,
  49. Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
  50. Constant::OPTION_MAX_REQUEST => 10 * 1024 * 1024,
  51. Constant::OPTION_SOCKET_BUFFER_SIZE => 10 * 1024 * 1024,
  52. Constant::OPTION_BUFFER_OUTPUT_SIZE => 10 * 1024 * 1024,
  53. Constant::OPTION_UPLOAD_MAX_FILESIZE => 10 * 1024 * 1024,
  54. ],
  55. 'callbacks' => [
  56. Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
  57. Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
  58. Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
  59. ],
  60. ];