அனைத்து மொழிகளும் ஃப்ரேம்வொர்க்குகளும்
ReactPHP PHP
/pixel.gif க்கு வரும் ரெக்வெஸ்ட்களுக்கு empty GIF மூலம் பதிலளிக்கும், ReactPHP க்கான PHP ஸ்னிப்பெட். GIF ஸ்டார்ட்அப்பில் ஒருமுறை மட்டுமே டீகோட் செய்யப்படுகிறது.
ReactPHP 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'));
இந்த ஸ்னிப்பெட்டை ரன் செய்து, அது திருப்பித் தந்த பைட்களை ஒப்பிட்டுப் பார்த்தோம்.
சரிபார்
curl -sI http://localhost:8080/pixel.gif