0

I've made a form that is waiting for a file. Once it's submitted, the file is uploaded to a remote server through the ftp_put() function. The problem is that it take something like 2/3 minuts.

I tried removing lines one by one to find out what's wrong and it's the call to ftp_put() that is taking so much time. The file is only 20Ko. Is there a way to upload the file in an other thread or something ?

EDIT : Here is my php code.

  $file = $_FILES['attachment']['tmp_name'];
  $ext = pathinfo($_FILES['attachment']['name'], PATHINFO_EXTENSION);
  $remote_file = '/cv_'.$_POST['first_name'].'_'.$_POST['last_name'].'_'.strval(time()).'.'.$ext;
  $ftp_server = 'xxxxxxxxx';
  $ftp_user_name = 'xxxxxx';
  $ftp_user_pass = 'xxxxxx';

  $conn_id = ftp_connect($ftp_server);
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
  if (!ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) /* This line is taking so long */
  {
    echo "There was a problem uploading the file $file\n";
  }
  ftp_close($conn_id);

EDIT 2 : The file is correctly uploaded after a few minuts. The code is working fine and fast on localhost, but when it's on the production server, it starts taking a long time.

6
  • So... why is it taking so much time? Isn't that what you should be trying to find out?
    – Jon
    Jul 11, 2014 at 8:46
  • Well I already tried... But the file is being uploaded very fast through a command in shell or ftp client.
    – Aeradriel
    Jul 11, 2014 at 11:58
  • What did you try exactly?
    – Jon
    Jul 11, 2014 at 12:05
  • You mean in PHP or to test the upload through command line or ftp client ? I've edited my post to provide my code.
    – Aeradriel
    Jul 11, 2014 at 12:11
  • No, I mean things like looking at the FTP server's logs and/or live network traffic to see why exactly the upload is taking so long.
    – Jon
    Jul 11, 2014 at 12:59

1 Answer 1

5

Solved it enabling passive mode.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.