PHP Streaming video handler

别来无恙 提交于 2019-12-05 13:56:10
Marc B

curl_exec() isn't designed for streaming output. It'll return only when the http request is completed. For a streaming request, that would theoretically be "never", and you'll just be filling up a memory buffer somewhere.

Check this answer for workarounds: Manipulate a string that is 30 million characters long

WebAdmin at dekho-ji.com

Yes, its easy to do. No need to set those headers manually. Let the server do it automatically.

Heres a working script which I wrote for a video streaming proxy -

ini_set('memory_limit','1024M');

set_time_limit(3600);

ob_start();

**// do any user checks here - authentication / ip restriction / max downloads / whatever**

**// if check fails, return back error message**

**// if check succeeds, proceed with code below**

if( isset($_SERVER['HTTP_RANGE']) )

$opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE'];

$opts['http']['method']= "HEAD";

$conh=stream_context_create($opts);

$opts['http']['method']= "GET";

$cong= stream_context_create($opts);

$out[]= file_get_contents($real_file_location_path_or_url,false,$conh);

$out[]= $http_response_header;

ob_end_clean();

array_map("header",$http_response_header);

readfile($real_file_location_path_or_url,false,$cong);

Try a solution like in this page: Streaming POST data through PHP cURL I'm gonna try it myself to see if it works, but thought I post this here before I get distracted and forget about this question :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!