server to server copy script stops in the middle of transfer

Discussion in 'PHP' started by zuly, Mar 11, 2009.

  1. #1
    hello, i need some help i use this script
    <?php
    $source = 'http://www.site.com/file.zip';
    $target = 'file.zip';
    
    if (@copy($source, $target))
    {
        echo 'File copied';
    }
    else
    {
        echo 'Could not copy file';
    }
    ?>
    Code (markup):
    everything works great if i'm copying smaller files, largest one i copied so far was 13 MB, but i tried to copy a file that has 94 MB and it stops on 23MB, a file of 20 MB stops on 16MB, i dont' know what the problem was.

    I suspected on 2 things,

    1.upload size limit, but it is not that, limit is 64M, ok i couldn't copy the 94 one, but the 20 MB one should work

    and i received an explination that it is the memory limit cause it is on 64M, is that the problem?

    If it is how can i change it and make it work

    thanks in advance
     
    zuly, Mar 11, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Upload limit isn't relevant in this case. It's most likely execution time - check whether it's taking too long to read the file from the remote server.

    It's possible that copy() was written in a very lazy way and tries to hold the whole thing in memory when using the URL wrappers but I sure hope that's not true.
     
    SmallPotatoes, Mar 11, 2009 IP
    zuly likes this.
  3. adstiger

    adstiger Peon

    Messages:
    409
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You should check the following:
    Apache Time out
    Php Time out
     
    adstiger, Mar 11, 2009 IP
  4. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #4
    Two things to check out are these

    set_time_limit
    max_execution_time

    Seems like what Small Potatoes is saying is correct it is timeing out before it could download the whole file.

    ini_set('max_execution_time',0);

    .

    As for upload_max_filesize that is mostly for POST html forms. memory_limit could affect it, but you said you have it up to 64MB so that is a bunch already then.
     
    exodus, Mar 11, 2009 IP
  5. zuly

    zuly Well-Known Member

    Messages:
    317
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #5
    you guys/gals are life savers, after your advice i changed the script to work like this

    <?php
    
    ini_set('max_execution_time',0);
    $source = 'http://www.site.com/file.zip';
    $target = 'file.zip';
    
    if (@copy($source, $target))
    {
        echo 'File copied';
    }
    else
    {
        echo 'Could not copy file';
    }
    ?>
    Code (markup):
    and it works like a charm, rep added to all of you, thanks a million
    regards
     
    zuly, Mar 11, 2009 IP
  6. adstiger

    adstiger Peon

    Messages:
    409
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thankyou so much for adding rep. I saw it today only so replying late.
     
    adstiger, Apr 3, 2009 IP