0

I'm trying to serve a file via php, with the following PHP code:

header("Accept-Ranges: bytes");
header("Access-Control-Allow-Origin: *");
header("Cache-Control: no-cache, must-revalidate");
header('Content-Type: application/vnd.apple.mpegurl');

echo file_get_contents('path/to/file.m3u8');

This seems to work:

root@server:~curl -I -XGET http://example.com/path/to/file.php
HTTP/1.1 200 OK
Server: nginx/1.22.1
Date: Sat, 04 Feb 2023 15:23:41 GMT
Content-Type: application/vnd.apple.mpegurl
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/8.1.14
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Cache-Control: no-cache, must-revalidate

However when I put http://example.com/path/to/file.php in VLC, it does not play the video.

Here are the ???:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=3794805,RESOLUTION=1920x1080,CODECS="avc1.4d4028,mp4a.40.2"
https://another-domain/1080p/chunks.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1866000,RESOLUTION=1280x720,CODECS="avc1.4d401f,mp4a.40.2"
https://another-domain/720p/chunks.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1054041,RESOLUTION=854x480,CODECS="avc1.77.30,mp4a.40.2"
https://another-domain/480p/chunks.m3u8

I'm not sure what the problem is. What do I need to do to be able to serve this file with PHP?

AD7six
  • 63,116
  • 12
  • 91
  • 123
pico.vn
  • 11
  • 4
  • What is the question? Please edit to clarify – AD7six Feb 04 '23 at 17:17
  • I did as you said – pico.vn Feb 05 '23 at 02:45
  • That is not what I said :). The formatting/structure here is a real distraction. I’ll edit the question for you this time (read the edit note :) ), please do this yourself in future – AD7six Feb 05 '23 at 11:39
  • The problem is very likely adding a `accept-ranges` header but the code does not handle `accept-ranges` requests. Please edit the question to address these questions: 1) can VLC load the file on disk? 2) Can VLC load the file served as a static file (i.e. put `file.m3u8` in the webroot and load `http://localhost/file.m3u8`)? - alternatively after downloading the php-served file 3) Assuming 'yes', what are the headers the webserver is returning for the file directly, and what is the difference to the php-generated headers? 4) most importantly: Why serve this file via php at all? – AD7six Feb 05 '23 at 11:43
  • The question is not m3u8 files specific, effectively you're just asking how to stream/serve files via php - I'd say simply: don't do that :). Here's a reference you may find useful [Fastest Way to Serve a File Using PHP](https://stackoverflow.com/q/3697748/761202) – AD7six Feb 05 '23 at 11:47
  • It seems to have worked for some reason, thanks for your enthusiasm – pico.vn Feb 06 '23 at 16:19

0 Answers0