emptygif
Langue: Français

Tous les langages et frameworks

Symfony PHP

Un extrait PHP pour Symfony qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

Symfony PHP

Installer
composer create-project symfony/skeleton app
Fichier
PixelController.php
Lancer
symfony server:start --port=8080
<?php

// src/Controller/PixelController.php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

final class PixelController
{
    private const GIF_BASE64 = 'R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';

    #[Route('/pixel.gif', name: 'pixel', methods: ['GET'])]
    public function __invoke(): Response
    {
        $gif = base64_decode(self::GIF_BASE64);

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

Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.

Vérifier

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

Site officiel: Symfony

Autres extraits en PHP