php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40389 ftp_put() function is very slow
Submitted: 2007-02-07 15:26 UTC Modified: 2007-02-07 16:07 UTC
From: afuzaylov at mlgpro dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.0 OS: windows xp
Private report: No CVE-ID: None
 [2007-02-07 15:26 UTC] afuzaylov at mlgpro dot com
Description:
------------
Hi. I have created a small php file to FTP .swf files to another server. It seems to run very very slow compared to another FTP program. It takes filezilla 1.5 minutes to upload 31MB .swf file, while it takes PHP to upload it about 3 hours.

I am running on windows xp apache2, PHP 5.2.

Reproduce code:
---------------
function ftp($file_name) {
  $conn_id = ftp_connect(FTP_SERVER);
  $login_result = ftp_login($conn_id, FTP_USERNAME, FTP_PASSWORD);
  if ($conn_id && $login_result) {
    set_time_limit(60 * 60 * 4); // 4 hours from now
    $upload = ftp_put($conn_id, FTP_PATH . $file_name, DIRECTORY_DESTINATION . $file_name, FTP_BINARY);
  }
  ftp_close($conn_id);
  if ($upload) { return TRUE; }
  return FALSE;
}

  $file_name = "test.swf";

  $uploaded = ftp($file_name);
  if ($uploaded) {
    // do something
  } else {
    // do something
  }
}

Expected result:
----------------
It should not take 3 hours to upload a file while it takes other FTP programs less than 2 minutes.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-07 15:35 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2007-02-07 15:46 UTC] afuzaylov at mlgpro dot com
Steps to reproduce:
1) Please download 32MB file from here:
http://media.mlgpro.com/uv/2007/0206/117/1Adc06430e456ca66f8f572f6a5fe69308X0J500O1.swf
2) Save the following PHP script in the same dir with the above downloaded file.
3) Change values for constants to reflect your dirs and passwords.
4) Run the script and time the amount it will take to complete (be prepared to spend 3 hours if you will run into the same problem as I have).
5) Now run any other FTP program to FTP the same file to the same server.
6) Compare times.

<?php
function ftp($file_name) {
  $conn_id = ftp_connect(FTP_SERVER);
  $login_result = ftp_login($conn_id, FTP_USERNAME, FTP_PASSWORD);
  if ($conn_id && $login_result) {
    set_time_limit(60 * 60 * 4); // 4 hours from now
    $upload = ftp_put($conn_id, FTP_PATH . $file_name, DIRECTORY_DESTINATION . $file_name, FTP_BINARY);
  }
  ftp_close($conn_id);
  if ($upload) { return TRUE; }
  return FALSE;
}

$file_name = "test.swf";
$started = time();
$uploaded = ftp($file_name);
$ttime = time() - $started;
if ($uploaded) {
  echo "CONGRATULATIONS!";
} else {
  echo "FAILED!";
}
echo " Total time took: $ttime seconds";
?>
 [2007-02-07 15:49 UTC] afuzaylov at mlgpro dot com
Oops, I'm sorry, I forgot to define constants. Please put the following code on the second line of the code I just submitted above (right after <?php)

define('FTP_SERVER', '');
define('FTP_USERNAME', '');
define('FTP_PASSWORD', '');
define('FTP_PATH', ''); // where to put your file on the server
define('DIRECTORY_DESTINATION', ''); // where your file is currently located on your local machine
 [2007-02-07 16:07 UTC] tony2001@php.net
It takes less then a couple of minutes, which is the same result I get using any other FTP client.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 15:01:35 2025 UTC