Open robinscholz opened 5 years ago
Closing this, since it seems to be a problem with the PHP localhost server, unrelated to Kirby.
@robinscholz The same problem occurs with us not only with a PHP localhost server. Can you recommend server settings that worked for you?
@robinscholz no, it's not a problem with the PHP localhost server.
On the very first request for a video (that's not in the media
folder), the request is handled in PHP by Kirby which doesn't add the required Range
header, as discussed on Stack Overflow. Therefore, the video doesn't play on Safari.
On subsequent requests, the video file now exists in the media
folder, so the request is not getting passed to PHP and is getting served by Apache instead, and it sets all the correct headers (and also returns HTTP 206).
You should reopen this. We have this issue on production and we always have to purge the cache the first time a new video is uploaded because it's incorrectly served.
Ideas where to tackle this:
Kirby\Http\Reponse::file()
would need to differentiate between full file requests and range requests$handle = fopen($file, 'rb');
fseek($handle, $start);
if ($end === $size) {
fpassthru($handle);
} else {
$step = 8 * KB_IN_BYTES;
$remaining = $end - $start;
while (
$remaining &&
!feof($handle) &&
$chunk = fread($handle, min($step, $remaining))
) {
$remaining -= strlen($step);
echo $chunk;
flush();
}
}
fclose( $handle );
The question is if the Response
class should directly access the Request
headers to determine the correct behavior or if it should be told which mode to use.
@lukasbestle the easier way would probably yo do it within the/a Response
class - just because otherwise we'd have to check quite a few spots in the code where the Response class would need to be told from outside.
Easiest, definitely. But won't we shoot ourselves in the foot by attaching the two classes so closely together? Especially because we need to get "the" request object from the app instance.
Maybe we could have a string|false|null $range = null
argument. If passed a string
, it will use that range. If passed false
, it will always output the full file. For null
it will lazily try to access the app request object. If that's not there or the Range
header does not exist, it will fall back to the full file.
I started something https://github.com/getkirby/kirby/pull/5153 Would love to hear from anyone who knows a bit about range requests 🙏
Describe the bug Safari needs the server to support byte-range requests. Instead of simply requesting the video, Safari first sends a byte range request:
and expects the response status
206
. Kirby currently responds with200
. Safari then aborts its request instead of sending various others for the complete range of bytes.To Reproduce Steps to reproduce the behavior: