By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,301 Members | 3,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,301 IT Pros & Developers. It's quick & easy.

file transfer from server to client

P: n/a
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
Mar 2 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Alex wrote:
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%,...).
[...]
Someone has an genius idea for me?
Most probably, your script is dying because it has used its 30 sec time
slice. You can try to feed a higher number to set_time_limit(), but I don't
recommend that.

For files that large, rely on the web server directly.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
Mar 2 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.