I want to download a WordPerfect document .wpd via my php app. I use the following code
We have several locations (buildings). When downloading a document in the building with the server, I have no problem, however if one of our remote locations attempts to download a document > 2mb it times out at 1.4 to 1.5 mb.
I have attempted to change the chunk size to 512, 1024 and 4096 none of which improve the situation. I am fairly sure it is because of our slow transfer speed we currently have.
Most likely I could solve the problem if I understood how to change the socket time out or if I could build in a loop that exits when the socket is not timing out.
Any suggestions or sample code that could help me overcome this limitation would be appreciated. The company is unfortunately not going to upgrade their data transfer connections at this time so that is not an option.
In the php manual I see the following code for adjusting the socket speed. However I am not sure how to intergrate the needed parts of this code into my code. I think I need the parts I have bolded.
Code:
function downLoadFile ($fullPath)
{
/*
Usage:
<a href="download.php?download_file=some_file.pdf">Download here</a>
*/
if ($fd = fopen ($fullPath, "rb")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
/*get file type from extention*/
$ext = strtolower($path_parts["extension"]);
/* add here more headers for diff. extensions */
switch ($ext)
{
case "pdf":
header("Content-type: application/pdf");
/* use 'attachment' to force a download */
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
break;
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
}
I have attempted to change the chunk size to 512, 1024 and 4096 none of which improve the situation. I am fairly sure it is because of our slow transfer speed we currently have.
Most likely I could solve the problem if I understood how to change the socket time out or if I could build in a loop that exits when the socket is not timing out.
Any suggestions or sample code that could help me overcome this limitation would be appreciated. The company is unfortunately not going to upgrade their data transfer connections at this time so that is not an option.
In the php manual I see the following code for adjusting the socket speed. However I am not sure how to intergrate the needed parts of this code into my code. I think I need the parts I have bolded.
Code:
<?php
[B]$fp = fsockopen("www.example.com", 80);[/B]
if (!$fp) {
echo "Unable to open\n";
} else {
fwrite($fp, "GET / HTTP/1.0\r\n\r\n");
[B]stream_set_timeout($fp, 2);[/B]
$res = fread($fp, 2000);
$info = stream_get_meta_data($fp);
fclose($fp);
[B]//use some sort of loop instead here for testing if socket has timed out. then resume when socket is clear
if ($info['timed_out'])[/B] {
echo 'Connection timed out!';
} else {
echo $res;
}
}
?>
Comment