start.php 867 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. use Mark\App;
  3. use Workerman\Timer;
  4. use Workerman\Protocols\Http\Response;
  5. require 'vendor/autoload.php';
  6. $api = new App('http://0.0.0.0:8080');
  7. $api->name = "Mark";
  8. $api->count = (int) shell_exec('nproc');
  9. $api->any('/plaintext', function () {
  10. global $date;
  11. return new Response(200, [
  12. 'Content-Type' => 'text/plain',
  13. 'Date' => $date
  14. ], 'Hello, World!');
  15. });
  16. $api->get('/json', function () {
  17. global $date;
  18. return new Response(200, [
  19. 'Content-Type' => 'application/json',
  20. 'Date' => $date
  21. ], \json_encode(['message' => 'Hello, World!']));
  22. });
  23. $date = gmdate('D, d M Y H:i:s').' GMT';
  24. $api->onWorkerStart = static function () {
  25. Timer::add(1, function () {
  26. global $date;
  27. $date = gmdate('D, d M Y H:i:s').' GMT';
  28. });
  29. };
  30. $api->reusePort = true;
  31. $api->start();