server.php 961 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-Slim';
  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. $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(DATE_RFC7231);
  32. Timer::add(1, static function() {
  33. self::$date = self::NAME . gmdate(DATE_RFC7231);
  34. });
  35. }
  36. }