start.php 838 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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->count = (int) shell_exec('nproc');
  8. $api->any('/plaintext', function () {
  9. global $date;
  10. return new Response(200, [
  11. 'Content-Type' => 'text/plain',
  12. 'Date' => $date
  13. ], 'Hello, World!');
  14. });
  15. $api->get('/json', function () {
  16. global $date;
  17. return new Response(200, [
  18. 'Content-Type' => 'application/json',
  19. 'Date' => $date
  20. ], \json_encode(['message' => 'Hello, World!']));
  21. });
  22. $date = gmdate('D, d M Y H:i:s').' GMT';
  23. $api->onWorkerStart = function () {
  24. Timer::add(1, function () {
  25. global $date;
  26. $date = gmdate('D, d M Y H:i:s').' GMT';
  27. });
  28. };
  29. $api->reusePort = true;
  30. $api->start();