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 示例