server.php 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require_once __DIR__ . '/vendor/autoload.php';
  3. use Adapterman\Adapterman;
  4. use Workerman\Worker;
  5. use Workerman\Lib\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->name = 'AdapterMan-Leaf';
  10. $http_worker->onWorkerStart = static function () {
  11. HeaderDate::init();
  12. //init();
  13. require __DIR__.'/index.php';
  14. };
  15. $http_worker->onMessage = static function ($connection) {
  16. $_SERVER['SCRIPT_NAME'] = 'index.php';
  17. $connection->send(run());
  18. };
  19. Worker::runAll();
  20. class HeaderDate
  21. {
  22. const NAME = 'Date: ';
  23. /**
  24. * Date header
  25. *
  26. * @var string
  27. */
  28. public static $date;
  29. public static function init(): void
  30. {
  31. self::$date = self::NAME . gmdate('D, d M Y H:i:s').' GMT';
  32. Timer::add(1, static function() {
  33. self::$date = self::NAME . gmdate('D, d M Y H:i:s').' GMT';
  34. });
  35. }
  36. }