Tempest PHP
適用於 Tempest 的 PHP 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
Tempest PHP
<?php
// app/PixelController.php: Tempest discovers the #[Get] route, no registration needed.
namespace App;
use Tempest\Http\Response;
use Tempest\Http\Responses\Ok;
use Tempest\Router\Get;
final readonly class PixelController
{
#[Get('/pixel.gif')]
public function __invoke(): Response
{
return new Ok(base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='))
->addHeader('Content-Type', 'image/gif')
->addHeader('Cache-Control', 'no-store');
}
}
我們執行了這段程式碼,並比對了它回傳的位元組。
驗證
curl -sI http://localhost:8080/pixel.gif