emptygif
语言: 简体中文

所有语言和框架

Slim PHP

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

Slim PHP

安装
composer require slim/slim slim/psr7
文件
index.php
运行
php -S 0.0.0.0:8080 index.php
<?php

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

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

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

$app = AppFactory::create();

$app->get('/pixel.gif', function (Request $request, Response $response) use ($gif) {
    $response->getBody()->write($gif);

    return $response
        ->withHeader('Content-Type', 'image/gif')
        ->withHeader('Content-Length', (string) strlen($gif))
        ->withHeader('Cache-Control', 'no-store');
});

$app->run();

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

验证

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

官方网站: Slim

更多 PHP 示例