file transfer from server to client

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    file transfer from server to client

    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="'.$fi lename.'"');
    //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.tx t", "a");
    fwrite($fd, "start of transfert\n");
    fclose($fd);

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

    $fd = fopen("debug.tx t", "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_abo rted() and
    connection_stat us()), 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
  • =?ISO-8859-15?Q?Iv=E1n_S=E1nchez_Ortega?=

    #2
    Re: file transfer from server to client

    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_eat_s_p_a _m_for_breakfas t@hotmail.com
    Jabber:ivansanc hez@jabber.org ; ivansanchez@kde talk.net

    Comment

    Working...