http_server.php 906 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. ini_set("memory_limit","512M");
  3. use Swoole\Coroutine as co;
  4. class Server
  5. {
  6. public $server;
  7. public $redisPool = [];
  8. public function run()
  9. {
  10. $this->server = new Swoole\Http\Server("0.0.0.0", 9502, SWOOLE_BASE);
  11. $this->server->set([
  12. 'worker_num' => 1,
  13. ]);
  14. // $this->server->on('Connect', [$this, 'onConnect']);
  15. $this->server->on('Request', [$this, 'onRequest']);
  16. // $this->server->on('Close', [$this, 'onClose']);
  17. $this->server->set(['trace_flags' => 1 << 15, 'log_level' => 0]);
  18. $this->server->start();
  19. }
  20. public function onRequest($request, $response)
  21. {
  22. $fd = $request->fd;
  23. co::create(function () {
  24. co::sleep(0.1);
  25. });
  26. $response->end(111);
  27. }
  28. }
  29. $server = new Server();
  30. Swoole\Coroutine::set(array(
  31. 'max_coroutine' => 1000,
  32. ));
  33. $server->run();