Swoole PHP
/pixel.gif へのリクエストに空の GIF を返す、Swoole 用の PHP スニペット。GIF は起動時に一度だけデコードします。
Swoole PHP
<?php
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;
$gif = base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
$server = new Server('0.0.0.0', 8080);
$server->set(['http_compression' => false]); // gzip only makes a tiny GIF bigger
$server->on('request', function (Request $request, Response $response) use ($gif) {
if ($request->server['request_uri'] !== '/pixel.gif') {
$response->status(404);
$response->end();
return;
}
$response->header('Content-Type', 'image/gif');
$response->header('Cache-Control', 'no-store');
$response->end($gif);
});
$server->start();
このスニペットは実行し、返されたバイト列を照合しました。
確認
curl -sI http://localhost:8080/pixel.gif