emptygif
언어: 한국어

모든 언어 및 프레임워크

FrankenPHP (worker mode) PHP

/pixel.gif 요청에 빈 GIF로 응답하는 FrankenPHP (worker mode)용 PHP 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.

FrankenPHP (worker mode) PHP

파일
index.php
실행
frankenphp php-server --listen :8080 --worker index.php
<?php

// Worker script: booted once, then handles requests in a loop.
ignore_user_abort(true);

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

$handler = static function () use ($gif): void {
    if (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) !== '/pixel.gif') {
        http_response_code(404);
        return;
    }
    header('Content-Type: image/gif');
    header('Content-Length: ' . strlen($gif));
    header('Cache-Control: no-store');
    echo $gif;
};

while (frankenphp_handle_request($handler)) {
    gc_collect_cycles();
}

이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.

확인

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

공식 사이트: FrankenPHP (worker mode)

PHP의 다른 예제