server.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require_once __DIR__ . '/vendor/autoload.php';
  3. use Adapterman\Adapterman;
  4. use Workerman\Worker;
  5. use Workerman\Lib\Timer;
  6. use Workerman\Protocols\Http;
  7. Adapterman::init();
  8. require __DIR__.'/app/index.php';
  9. $http_worker = new Worker('http://0.0.0.0:8080');
  10. $http_worker->count = (int) shell_exec('nproc') * 4;
  11. $http_worker->name = 'AdapterMan-Yii2';
  12. $http_worker->onWorkerStart = function () {
  13. WorkerTimer::init();
  14. //init();
  15. //require __DIR__.'/app/index.php';
  16. };
  17. $http_worker->onMessage = static function ($connection, $request) {
  18. $_SERVER['SCRIPT_FILENAME'] = '/app/index.php';
  19. $_SERVER['SCRIPT_NAME'] = '/index.php';
  20. Http::header(WorkerTimer::$date);
  21. $connection->send(
  22. handleWorkerman()
  23. );
  24. };
  25. class WorkerTimer
  26. {
  27. public static $date;
  28. public static function init()
  29. {
  30. self::$date = 'Date: '.gmdate('D, d M Y H:i:s').' GMT';
  31. Timer::add(1, function() {
  32. WorkerTimer::$date = 'Date: '.gmdate('D, d M Y H:i:s').' GMT';
  33. });
  34. }
  35. }
  36. Worker::runAll();