server.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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' => 'jsonrpc-http',
  19. 'type' => Server::SERVER_HTTP,
  20. 'host' => '0.0.0.0',
  21. 'port' => 9510,
  22. 'sock_type' => SWOOLE_SOCK_TCP,
  23. 'callbacks' => [
  24. // Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
  25. Event::ON_REQUEST => [Hyperf\JsonRpc\HttpServer::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. 'task_worker_num' => swoole_cpu_num(), //
  44. 'task_enable_coroutine' => false,
  45. ],
  46. 'callbacks' => [
  47. // Task callbacks
  48. Event::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
  49. Event::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
  50. Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
  51. Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
  52. Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
  53. ],
  54. ];