[GH-ISSUE #708] Problems in PHPStreamer - Byterange (Optimizations) #501

Closed
opened 2026-02-26 02:33:23 +03:00 by kerem · 1 comment
Owner

Originally created by @skeyby on GitHub (Jan 4, 2018).
Original GitHub issue: https://github.com/koel/koel/issues/708

Checking PHPStreamet Byterange stuff furthermore I think there's a specific condition that can be checked to improve performances.

That is when the browser asks for

Range: 0-

That is a (pretty silly IMHO) way to ask for a complete file, not a partial one.

Thus I'd change the code block around line 51 to something like this:

            } elseif ($range[1] === '') {
                if ($range[0] == 0) {
                        $start = 0;
                        $end = $fileSize -1;
                        $partial = false;
                } else {
                        // Second number missing, return from byte $range[0] to end
                        $start = (int) $range[0];
                        $end = $fileSize - 1;
                }
            } else {

I tested it and it works ok. It's also a great optimization because many load balancer / web accelerator will refuse to cache any content with a 206 http code (see for example apache 2.4 mod cache: https://httpd.apache.org/docs/2.4/caching.html ...

What Can be Cached?
The full definition of which responses can be cached by an HTTP cache is defined in RFC2616 Section 13.4 Response Cacheability, and can be summed up as follows:

Caching must be enabled for this URL. See the CacheEnable and CacheDisable directives.
The response must have a HTTP status code of 200, 203, 300, 301 or 410.
The request must be a HTTP GET request.
If the response contains an "Authorization:" header, it must also contain an "s-maxage", "must-revalidate" or "public" option in the "Cache-Control:" header, or it won't be cached.
If the URL included a query string (e.g. from a HTML form GET method) it will not be cached unless the response specifies an explicit expiration by including an "Expires:" header or the max-age or s-maxage directive of the "Cache-Control:" header, as per RFC2616 sections 13.9 and 13.2.1.
If the response has a status of 200 (OK), the response must also include at least one of the "Etag", "Last-Modified" or the "Expires" headers, or the max-age or s-maxage directive of the "Cache-Control:" header, unless the CacheIgnoreNoLastMod directive has been used to require otherwise.
If the response includes the "private" option in a "Cache-Control:" header, it will not be stored unless the CacheStorePrivate has been used to require otherwise.
Likewise, if the response includes the "no-store" option in a "Cache-Control:" header, it will not be stored unless the CacheStoreNoStore has been used.
A response will not be stored if it includes a "Vary:" header containing the match-all "*".

Originally created by @skeyby on GitHub (Jan 4, 2018). Original GitHub issue: https://github.com/koel/koel/issues/708 Checking PHPStreamet Byterange stuff furthermore I think there's a specific condition that can be checked to improve performances. That is when the browser asks for Range: 0- That is a (pretty silly IMHO) way to ask for a complete file, not a partial one. Thus I'd change the code block around line 51 to something like this: ``` } elseif ($range[1] === '') { if ($range[0] == 0) { $start = 0; $end = $fileSize -1; $partial = false; } else { // Second number missing, return from byte $range[0] to end $start = (int) $range[0]; $end = $fileSize - 1; } } else { ``` I tested it and it works ok. It's also a great optimization because many load balancer / web accelerator will refuse to cache any content with a 206 http code (see for example apache 2.4 mod cache: https://httpd.apache.org/docs/2.4/caching.html ... > What Can be Cached? > The full definition of which responses can be cached by an HTTP cache is defined in RFC2616 Section 13.4 Response Cacheability, and can be summed up as follows: > > Caching must be enabled for this URL. See the CacheEnable and CacheDisable directives. > The response must have a HTTP status code of 200, 203, 300, 301 or 410. > The request must be a HTTP GET request. > If the response contains an "Authorization:" header, it must also contain an "s-maxage", "must-revalidate" or "public" option in the "Cache-Control:" header, or it won't be cached. > If the URL included a query string (e.g. from a HTML form GET method) it will not be cached unless the response specifies an explicit expiration by including an "Expires:" header or the max-age or s-maxage directive of the "Cache-Control:" header, as per RFC2616 sections 13.9 and 13.2.1. > If the response has a status of 200 (OK), the response must also include at least one of the "Etag", "Last-Modified" or the "Expires" headers, or the max-age or s-maxage directive of the "Cache-Control:" header, unless the CacheIgnoreNoLastMod directive has been used to require otherwise. > If the response includes the "private" option in a "Cache-Control:" header, it will not be stored unless the CacheStorePrivate has been used to require otherwise. > Likewise, if the response includes the "no-store" option in a "Cache-Control:" header, it will not be stored unless the CacheStoreNoStore has been used. > A response will not be stored if it includes a "Vary:" header containing the match-all "*".
kerem closed this issue 2026-02-26 02:33:23 +03:00
Author
Owner

@phanan commented on GitHub (Jan 4, 2018):

Ha, TBH I didn't invent this bunch of code (I think I credited it as well). So if you think it can be optimized/improved, just send a PR over. Cheers!

<!-- gh-comment-id:355344881 --> @phanan commented on GitHub (Jan 4, 2018): Ha, TBH I didn't invent this bunch of code (I think I credited it as well). So if you think it can be optimized/improved, just send a PR over. Cheers!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/koel-koel#501
No description provided.