server.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_once __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';
  12. $http_worker->onWorkerStart = function () {
  13. WorkerTimer::init();
  14. //init();
  15. };
  16. $http_worker->onMessage = static function ($connection, $request) {
  17. $_SERVER['SCRIPT_FILENAME'] = '/app/index.php';
  18. $_SERVER['SCRIPT_NAME'] = '/index.php';
  19. Http::header(WorkerTimer::$date);
  20. $connection->send(
  21. handleWorkerman()
  22. );
  23. };
  24. class WorkerTimer
  25. {
  26. public static $date;
  27. public static function init()
  28. {
  29. self::$date = 'Date: '.gmdate('D, d M Y H:i:s').' GMT';
  30. Timer::add(1, function() {
  31. WorkerTimer::$date = 'Date: '.gmdate('D, d M Y H:i:s').' GMT';
  32. });
  33. }
  34. }
  35. Worker::runAll();