server.php 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require_once __DIR__ . '/vendor/autoload.php';
  3. use Adapterman\Adapterman;
  4. use Workerman\Worker;
  5. use Workerman\Timer;
  6. Adapterman::init();
  7. $http_worker = new Worker('http://0.0.0.0:8080');
  8. $http_worker->count = (int) shell_exec('nproc') * 4;
  9. $http_worker->reusePort = true;
  10. $http_worker->name = 'AdapterMan-Leaf';
  11. $http_worker->onWorkerStart = static function () {
  12. HeaderDate::init();
  13. //init();
  14. require __DIR__.'/index.php';
  15. };
  16. $http_worker->onMessage = static function ($connection) {
  17. $_SERVER['SCRIPT_NAME'] = 'index.php';
  18. $connection->send(run());
  19. };
  20. Worker::runAll();
  21. class HeaderDate
  22. {
  23. const NAME = 'Date: ';
  24. /**
  25. * Date header
  26. *
  27. * @var string
  28. */
  29. public static $date;
  30. public static function init(): void
  31. {
  32. self::$date = self::NAME . gmdate(DATE_RFC7231);
  33. Timer::add(1, static function() {
  34. self::$date = self::NAME . gmdate(DATE_RFC7231);
  35. });
  36. }
  37. }