Results 1 to 5 of 5
  1. #1

    PHP: Help! Concurrent ftp uploads.

    I'm trying to mirror some files from one dedicated box with PHP and FTP

    I want the files to upload concurrently to different servers
    instead of uploading to one server at a time.
    Any gurus know how to do this? Thanks!

    my code has been like:

    $conn_id = ftp_connect("iphere");
    // login with username and password
    $login_result = ftp_login($conn_id, "username", "pass");
    // upload the file
    $upload = ftp_put($conn_id, "/files/blah.bah","blah.bah", FTP_BINARY);
    // close the FTP stream

    but this only uploads one at a time. I was thinking forking but then
    I read forking isnt supposed to be used with webservers? Any help is appreciated!

  2. #2
    Join Date
    May 2004
    Lansing, MI, USA
    And thus you hit the problem where php isn't a fulll programming language. Don't get me wrong, I love it, but these things stuck.

    But if you get your host to compile pnctl stuff in, you can use threads.
    Jacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
    Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
    Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large

  3. #3
    i figured it out using system something along the lines of
    for loop
    system("php blah.php args >/dev/null &"

    where blah.php uploads by ftp and is run in the background.

  4. #4
    Join Date
    Sep 2005
    Southern California
    Assuming you have shell access:

    I would have just used a shell script, no reason to use php for something like this

    Assuming your host supports FXP, you could FXP the files.

    If your host does not provide shell access, then i probably would have used perl and done a simple fork()

  5. #5
    Join Date
    Jul 2003
    Since these operations are blocking (which means, execution stops till the operation is complete) you need to use threading -- as mentioned above, or fork the process to the shell.

    PHP is not really the best when it comes to this kind of stuff unless you have pntl compiled, and even then its a bit flaky.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts