简体   繁体   中英

PHP send http response GZIP large file

I am trying to set up an easy MOCK http response as a PHP script. Therefore I have this code:

<?php
$filename = "output.txt.gz";
$filesize = filesize($filename);
//ignore the next 3 lines
$handle = fopen($filename, "r");
$contents = fread($handle, $filesize);
fclose($handle);
header("HTTP/1.1 200 OK");
header("Content-Encoding: gzip");
header("Content-Type: text/xml;charset=UTF-8");
header('Content-Length: '.$filesize);
header("location: ".$filename);
?>

If I'm triggering the script with small data (1mb) it works fine, but for huge content like 80mb it does not!

What is going wrong and how to solve this?

not the best solution, but try to put this line at the begining of the code

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

edit

it seems you are having maybe timout issue, add this line also:

set_time_limit(0);

important: set_time_limit(0) will set the execute time to unlimited, this is not recommended but see if it solves your problem and if it does try to optimize the timeout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM