emptygif
語言: 繁體中文

所有語言和框架

Plain PHP (php-fpm, mod_php, php -S) PHP

適用於 Plain PHP (php-fpm, mod_php, php -S) 的 PHP 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Plain PHP (php-fpm, mod_php, php -S) PHP

檔案
index.php
執行
php -S 0.0.0.0:8080 index.php
<?php

// Front controller: works under php-fpm, Apache mod_php or the built-in server.
if (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) !== '/pixel.gif') {
    http_response_code(404);
    return;
}

$gif = base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

header('Content-Type: image/gif');
header('Content-Length: ' . strlen($gif));
header('Cache-Control: no-store');
echo $gif;

我們執行了這段程式碼,並比對了它回傳的位元組。

驗證

curl -sI http://localhost:8080/pixel.gif

官方網站: Plain PHP (php-fpm, mod_php, php -S)

更多 PHP 範例