emptygif
语言: 简体中文

所有语言和框架

ReactPHP PHP

一个用于 ReactPHP 的 PHP 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。

ReactPHP PHP

安装
composer require react/http
文件
server.php
运行
php server.php
<?php

use Psr\Http\Message\ServerRequestInterface;
use React\Http\HttpServer;
use React\Http\Message\Response;
use React\Socket\SocketServer;

require __DIR__ . '/vendor/autoload.php';

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

$http = new HttpServer(function (ServerRequestInterface $request) use ($gif) {
    if ($request->getMethod() !== 'GET' || $request->getUri()->getPath() !== '/pixel.gif') {
        return new Response(Response::STATUS_NOT_FOUND);
    }

    return new Response(Response::STATUS_OK, [
        'Content-Type' => 'image/gif',
        'Cache-Control' => 'no-store',
    ], $gif);
});

$http->listen(new SocketServer('0.0.0.0:8080'));

我们运行了此代码片段,并比对了它返回的字节。

验证

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

官方网站: ReactPHP

更多 PHP 示例