3
I have two servers server1 and the server2, the server2 only accept request from server1 if it is another ip it returns 404, my website is on server1 and the files for download on server2, I made the following script to return the download of server2:
ob_start();
set_time_limit(0);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$r = curl_exec($ch);
curl_close($ch);
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header('Cache-Control: private', false);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . basename($url) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . strlen($r)); // provide file size
header('Connection: close');
echo $r;
However when the file is too large it displays the following memory error message which would be the solution for it?
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 139642559 bytes) in
Try increasing the limit with the command:
ini_set("memory_limit","512M");
– Math
@Math the prank is not good practice if you don’t have a dedicated server. You can consume server resources with PHP.
– Jorge B.
@Jorgeb. thanks for the info, I’m not good at php. But so what? At least it solves?
– Math
Leandro anyway take a look at this answer: http://answall.com/a/15641/7210
– Jorge B.
Yeah, it solves @Math. But for example I have a company server with only 2G of RAM, if I use 512 only for PHP will leave the other services to bread and water ;)
– Jorge B.
@Jorgeb. Would have some other way to return the download ?
– Leandro Costa
Leandro also looking for this answer. To this day I do not know how to best Download and Upload in PHP.
– Jorge B.