emptygif
Harshe: Hausa

Duk harsuna da frameworks

Workerman PHP

Snippet na PHP don Workerman da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.

Workerman PHP

Girkawa
composer require workerman/workerman
Fayil
server.php
Gudanar
php server.php start
<?php

use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;
use Workerman\Worker;

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

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

$worker = new Worker('http://0.0.0.0:8080');

$worker->onMessage = function (TcpConnection $connection, Request $request) use ($gif) {
    if ($request->path() !== '/pixel.gif') {
        $connection->send(new Response(404));
        return;
    }
    $connection->send(new Response(200, [
        'Content-Type' => 'image/gif',
        'Cache-Control' => 'no-store',
    ], $gif));
};

Worker::runAll();

Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.

Duba shi

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

Shafin hukuma: Workerman

Ƙari a PHP