remote upload in background

Discussion in 'PHP' started by um., Aug 4, 2010.

  1. #1
    I have a remote download script in which i am using curl to download files

    <?php
     
    $urls=array(
    'http://f.askapache.com/mp3/12-lessons-for-those-afraid-of-css.mp3',
    'http://f.askapache.com/mp3/27-request-methods-for-use-with-apache-and-rewritecond-and-htaccess.mp3',
    'http://f.askapache.com/mp3/301-redirect-with-mod_rewrite-or-redirectmatch.mp3',
    'http://f.askapache.com/mp3/404-errorpages.mp3',
    'http://f.askapache.com/mp3/503-service-temporarily-unavailable.mp3',
    'http://f.askapache.com/mp3/adsense-robots.mp3',
    'http://f.askapache.com/mp3/alexa-toolbar-firefox.mp3',
    'http://f.askapache.com/mp3/allowing-access-from-1-static-ip-and-deny-the-rest.mp3',
    'http://f.askapache.com/mp3/apache-authentication-in-htaccess.mp3');
     
    $save_to='/home/user/public_html/mp3/';
     
    $mh = curl_multi_init();
    foreach ($urls as $i => $url) {
        $g=$save_to.basename($url);
        if(!is_file($g)){
            $conn[$i]=curl_init($url);
            $fp[$i]=fopen ($g, "w");
            curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]);
            curl_setopt ($conn[$i], CURLOPT_HEADER ,0);
            curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,60);
            curl_multi_add_handle ($mh,$conn[$i]);
        }
    }
    do {
        $n=curl_multi_exec($mh,$active);
    }
    while ($active);
    foreach ($urls as $i => $url) {
        curl_multi_remove_handle($mh,$conn[$i]);
        curl_close($conn[$i]);
        fclose ($fp[$i]);
    }
    curl_multi_close($mh);
    ?>
    PHP:
    but the problem is if the browser is closed it effect the downloading of file and downloading become stop so how i use shell_exec command so that if the browser is closed it doesnot effect my downloading?

    need really help THANKS
     
    um., Aug 4, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    i think you should use java here...
    use shell_exec
    create a .jar file that will handle all your parameters and will handle the process regardless if browser is closed.
     
    bartolay13, Aug 4, 2010 IP
  3. um.

    um. Greenhorn

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #3

    Can you share any code regarding this?
     
    um., Aug 4, 2010 IP
  4. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    set the script running though shell / via a cron job? php script.php
     
    themullet, Aug 4, 2010 IP
  5. um.

    um. Greenhorn

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #5
    i want to set a script through shell. have you ever use rapishare.com remote upload.. i want exactly like this ..
     
    um., Aug 4, 2010 IP
  6. um.

    um. Greenhorn

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #6
    Someone know how to create this?
     
    um., Aug 6, 2010 IP
  7. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #7
    First, you need to make sure that you have the privilege to run commands in the shell. Second, you need to read the documentation of shell_exec - as you can see, it's quite simple, one parameter is the command string and the return is the output of the command. Third, you need to have enough knowledge in running shell commands. Luckily, all you gotta do is download, this can be done with lwp-download command. With it, you won't need cURL. Try the following:
    
    $urls=array(
    'http://f.askapache.com/mp3/12-lessons-for-those-afraid-of-css.mp3',
    'http://f.askapache.com/mp3/27-request-methods-for-use-with-apache-and-rewritecond-and-htaccess.mp3',
    'http://f.askapache.com/mp3/301-redirect-with-mod_rewrite-or-redirectmatch.mp3',
    'http://f.askapache.com/mp3/404-errorpages.mp3',
    'http://f.askapache.com/mp3/503-service-temporarily-unavailable.mp3',
    'http://f.askapache.com/mp3/adsense-robots.mp3',
    'http://f.askapache.com/mp3/alexa-toolbar-firefox.mp3',
    'http://f.askapache.com/mp3/allowing-access-from-1-static-ip-and-deny-the-rest.mp3',
    'http://f.askapache.com/mp3/apache-authentication-in-htaccess.mp3');
    foreach($urls as $url) {
    $output = shell_exec("lwp-download $url");
    echo "<pre>$output</pre>";
    }
    
    PHP:
    But I'm not sure if it actually finishes all of the download because I'm not sure if PHP is gonna pause and wait for a download to finish, most likely it will. As you can see, PHP goes in a loop and it needs to run the shell command 9 times to download those nine files. So, if the user closes the browser, same thing might happen. I'm not very familiar with shell, but I believe the shell also has a loop command. :)
     
    Last edited: Aug 6, 2010
    Rainulf, Aug 6, 2010 IP
  8. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #8
    maybe threads with the shell_exec in there
     
    themullet, Aug 6, 2010 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    Last edited: Aug 7, 2010
    nico_swd, Aug 7, 2010 IP