server.php 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. 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->reusePort = true;
  11. $http_worker->name = 'AdapterMan-Yii2';
  12. $http_worker->onWorkerStart = static function () {
  13. WorkerTimer::init();
  14. };
  15. $http_worker->onMessage = static function ($connection) {
  16. $_SERVER['SCRIPT_FILENAME'] = '/app/index.php';
  17. $_SERVER['SCRIPT_NAME'] = '/index.php';
  18. header(WorkerTimer::$date);
  19. $connection->send(
  20. handleWorkerman()
  21. );
  22. };
  23. class WorkerTimer
  24. {
  25. public static $date;
  26. public static function init()
  27. {
  28. self::$date = 'Date: ' . gmdate(DATE_RFC7231);
  29. Timer::add(1, function() {
  30. WorkerTimer::$date = 'Date: ' . gmdate(DATE_RFC7231);
  31. });
  32. }
  33. }
  34. Worker::runAll();