emptygif
Lingua: Italiano

Tutti i linguaggi e framework

ReactPHP PHP

Uno snippet PHP per ReactPHP che risponde alle richieste a /pixel.gif con la GIF vuota, decodificata una sola volta all'avvio.

ReactPHP PHP

Installa
composer require react/http
File
server.php
Esegui
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'));

Abbiamo eseguito questo snippet e confrontato i byte che ha restituito.

Verifica

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

Sito ufficiale: ReactPHP

Altro in PHP