I am using this code to download a package from server A and put it in server B (copy)..but it does not work always, sometimes transfer does not get completed, file is not complete and some times it goes well. Can I improve this code in anyway or use cURL to do the same thing?
This is my code:
// from server a to server b
$filename = 'http://domain.com/file.zip';
$dest_folder = TEMPPATH.'/';
$out_file = @fopen(basename($filename), 'w');
$in_file = @fopen($filename, 'r');
if ($in_file && $out_file) {
while ($chunk = @fgets($in_file)) {
@fputs($out_file, $chunk);
}
@fclose($in_file);
@fclose($out_file);
$zip = new ZipArchive();
$result = $zip->open(basename($filename));
if ($result) {
$zip->extractTo($dest_folder);
$zip->close();
}
}
Problem is that it is not consistent. It does not get transfered all times, many times it comes missing and the script does not run well.
or
Really though, you need to figure out why it is failing. Is the zip operation killing it? Is the php script timing out because it took too long to execute? Is it running out of memory? Is the server on the other end timing out? Get some error reporting and debug data and try to figure out why it’s not working. The code you have should be fine, and reliable.