nginx - php proxy remote file download -


i willing "proxy" file located on remote server (let's call server b) , force download visitor, server a.

only server can access ressource on server b (ip address secured). ressource can weight few gigabytes.

here code far:

header('content-type: application/octet-stream'); header('content-disposition: attachment; filename='.$filename); header('content-transfer-encoding: chunked');  header('expires: 0'); header('cache-control: must-revalidate, post-check=0, pre-check=0'); header('pragma: public'); $stream = fopen('php://output', 'w'); $ch = curl_init($ruri); curl_setopt($ch, curlopt_readfunction, function($ch, $fd, $length) use ($stream) {     return fwrite($stream, fread($fd, $length)); }); curl_exec($ch); curl_close($ch); 

it works partially.

problem number 1:

  • the visitor cannot browse page of website on server while downloading ressource. why?

problem number 2:

  • it not support pause or resume download. apparently can solve using "range" headers. did not try yet since "problem number 1" big problem, , solve first before going further in direction.

please note:

  • i not want ressource downloaded on server a's disk before serving visitor, want "forwarded" directly visitor (aka "proxy"?)
  • i read posts readfile() , file_get_content(), tried, same problems. not mentionning how these functions "stress" server (cpu, memory), big files.
  • isn't there way more efficiently? mean without php, rather trough apache or nginx?


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -