Web Hosting Talk







View Full Version : PHP: Help! Concurrent ftp uploads.


haporn
11-18-2006, 07:18 PM
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
ftp_close($conn_id);

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!

WO-Jacob
11-18-2006, 08:05 PM
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. :)

haporn
11-18-2006, 11:26 PM
i figured it out using system :) something along the lines of
for loop
system("php blah.php args >/dev/null &"
end

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

localhost127
11-19-2006, 01:10 AM
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()

Burhan
11-19-2006, 02:13 AM
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.