You are here: file transfer from server to client « PHP Language « IT news, forums, messages
file transfer from server to client

Posted by Alex on 03/02/07 00:22

Hello,

I'm trying to write a little php script to transfert some
files from a server to clients (web/http).

It's working fin with small files. But transfering big files
(try on 1Gb) failed! The transfert is stoped randomly (sometimes
at 25%, sometimes at 75%,...).

And I don't understand why?! :/

Here, a part of my php script:

- Firstly, I'm sending the http headers

header('HTTP/1.1 200 OK');
header('Status: 200 OK');
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2,
date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");

header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header('Accept-Ranges: bytes');
header('Content-Transfer-Encoding: Binary');
header('Content-Type: application/force-download');
//header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
//header("Content-Disposition: inline; filename=$name");
header('Content-Length: '.$length);


- After that, I have a loop to send the content of the file
(and I'm writing in same time a debuf file on the server)

$fd = fopen("debug.txt", "a");
fwrite($fd, "start of transfert\n");
fclose($fd);

while(true) {
if (connection_aborted()) {
$fd = fopen("debug.txt", "a");
fwrite($fd, "connection aborted\n");
fclose($fd);
break ;
} else if (connection_status() != 0) {
$fd = fopen("debug.txt", "a");
fwrite($fd, "connection status\n");
fclose($fd);
break ;
} else if (feof($fp)) {
$fd = fopen("debug.txt", "a");
fwrite($fd, "end of file\n");
fclose($fd);
break ;
} else {
print(fread($fp, 1024*8));
flush();
}
}

$fd = fopen("debug.txt", "a");
fwrite($fd, "end of transfert\n");
fclose($fd);





So, the first thing I've noticed is that
header('Content-Length: '.$length);
give the correct file size!
(wget my_script.php show the correct file size to be transfer).

The second thing is that the debug file contains only this:
"start of transfer
start of transfer
start of transfer
...."
(The wget command re-start the download of the file when
the transfer is closed before the end and the wget command
write on the screen: "connection closed").

I'm trying to delete the 2 tests (connection_aborted() and
connection_status()), but the same bug appears!
Identically bug when I'm trying to read the file not with
1024*8 block size, but with only 1024 size.

Someone has an genius idea for me?

Thanks (ans sorry for my bad english),

--
Alex

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация