12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- require_once __DIR__.'/vendor/autoload.php';
- require_once __DIR__.'/fortune.php';
- require_once __DIR__.'/dbraw.php';
- require_once __DIR__.'/updateraw.php';
- use Workerman\Protocols\Http;
- use Workerman\Worker;
- $http_worker = new Worker('http://0.0.0.0:8080');
- $http_worker->count = (int) shell_exec('nproc') ?? 64;
- $http_worker->onWorkerStart = function () {
- global $pdo;
- $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world;charset=utf8',
- 'benchmarkdbuser', 'benchmarkdbpass');
- };
- $http_worker->onMessage = function ($connection) {
- global $pdo;
- Http::header('Date: '.gmdate('D, d M Y H:i:s').' GMT');
- switch (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)) {
- case '/plaintext':
- Http::header('Content-Type: text/plain');
- $connection->send('Hello, World!');
- break;
- case '/json':
- Http::header('Content-Type: application/json');
- $connection->send(json_encode(['message' => 'Hello, World!']));
- break;
- case '/db':
- Http::header('Content-Type: application/json');
- $connection->send(dbraw($pdo));
- break;
- case '/fortune':
- Http::header('Content-Type: text/html; charset=utf-8');
- $connection->send(fortune($pdo));
- break;
- case '/update':
- Http::header('Content-Type: application/json');
- $connection->send(updateraw($pdo));
- break;
- //case '/info':
- // Http::header('Content-Type: text/plain');
- // ob_start();
- // phpinfo();
- // $connection->send(ob_get_clean());
- //default:
- // $connection->send('error');
- }
- };
- Worker::runAll();
|