emptygif
Wika: Filipino

Lahat ng language at framework

Workerman PHP

Isang PHP snippet para sa Workerman na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

Workerman PHP

I-install
composer require workerman/workerman
File
server.php
Patakbuhin
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();

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: Workerman

Iba pa sa PHP