server.php 970 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. require __DIR__.'/app/index.php';
  8. $http_worker = new Worker('http://0.0.0.0:8080');
  9. $http_worker->count = (int) shell_exec('nproc') * 4;
  10. $http_worker->name = 'AdapterMan-Yii2';
  11. $http_worker->onWorkerStart = static function () {
  12. WorkerTimer::init();
  13. };
  14. $http_worker->onMessage = static function ($connection) {
  15. $_SERVER['SCRIPT_FILENAME'] = '/app/index.php';
  16. $_SERVER['SCRIPT_NAME'] = '/index.php';
  17. header(WorkerTimer::$date);
  18. $connection->send(
  19. handleWorkerman()
  20. );
  21. };
  22. class WorkerTimer
  23. {
  24. public static $date;
  25. public static function init()
  26. {
  27. self::$date = 'Date: ' . gmdate(DATE_RFC7231);
  28. Timer::add(1, function() {
  29. WorkerTimer::$date = 'Date: ' . gmdate(DATE_RFC7231);
  30. });
  31. }
  32. }
  33. Worker::runAll();