emptygif
言語: 日本語

すべての言語・フレームワーク

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

/pixel.gif へのリクエストに空の GIF を返す、Plain PHP (php-fpm, mod_php, php -S) 用の PHP スニペット。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 の他の例