server.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. use App\Http\Kernel as HttpKernel;
  4. use Hyperf\Server\Event;
  5. use Hyperf\Server\Server;
  6. use Swoole\Constant;
  7. return [
  8. 'mode' => SWOOLE_PROCESS,
  9. 'servers' => [
  10. [
  11. 'name' => 'http',
  12. 'type' => Server::SERVER_HTTP,
  13. 'host' => env('HTTP_SERVER_HOST', '0.0.0.0'),
  14. 'port' => (int) env('HTTP_SERVER_PORT', 9501),
  15. 'sock_type' => SWOOLE_SOCK_TCP,
  16. 'callbacks' => [
  17. Event::ON_REQUEST => [HttpKernel::class, 'onRequest'],
  18. ],
  19. ],
  20. ],
  21. 'kernels' => [
  22. 'http' => HttpKernel::class,
  23. ],
  24. 'settings' => [
  25. 'document_root' => base_path('public'),
  26. 'enable_static_handler' => true,
  27. Constant::OPTION_ENABLE_COROUTINE => true,
  28. Constant::OPTION_WORKER_NUM => env('SERVER_WORKERS_NUMBER', swoole_cpu_num()),
  29. Constant::OPTION_PID_FILE => base_path('runtime/hypervel.pid'),
  30. Constant::OPTION_OPEN_TCP_NODELAY => true,
  31. Constant::OPTION_MAX_COROUTINE => 100000,
  32. Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
  33. Constant::OPTION_MAX_REQUEST => 100000,
  34. Constant::OPTION_SOCKET_BUFFER_SIZE => 2 * 1024 * 1024,
  35. Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
  36. ],
  37. 'callbacks' => [
  38. Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
  39. Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
  40. Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
  41. ],
  42. ];