CodeIgniter 4 PHP
ตัวอย่างโค้ด PHP สำหรับ CodeIgniter 4 ที่ตอบคำขอไปยัง /pixel.gif ด้วย GIF ว่าง ซึ่งถอดรหัสเพียงครั้งเดียวตอนเริ่มทำงาน
CodeIgniter 4 PHP
<?php
// app/Config/Routes.php
use CodeIgniter\Router\RouteCollection;
/** @var RouteCollection $routes */
$routes->get('/', 'Home::index');
$routes->get('/pixel.gif', static fn () => service('response')
->setContentType('image/gif', '')
->setHeader('Cache-Control', 'no-store')
->setBody(base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')));
เรารันตัวอย่างโค้ดนี้และเทียบไบต์ที่ได้กลับมาแล้ว
ตรวจสอบ
curl -sI http://localhost:8080/pixel.gif