I'm building a web server and i want my php script to transfer large amounts of data. Which method should i use?
I'm talking about over 20 mb sized strings. I tried to echo them but script cannot print more than 5-6 mb after 1-2 minutes. After that I tried to split strings into blocks and print them, still no luck. Compressing didn't work either since the strings are base64 encoded.
As you can see here, i tried to write the data into a file and download it:
$payload = "my large string";
file_put_contents("payload.txt", $payload);
$download_rate = 100;
$file = fopen("payload.txt", "r");
while(!feof($file)) {
print fread($file, round($download_rate * 1024));
flush();
ob_end_clean();
}
fclose($file);