FTP连接太多,无法接受更多 [英] Too many FTP connections, can't accept more

查看:1635
本文介绍了FTP连接太多,无法接受更多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误讯息:


警告: ftp_login():我无法接受在第58行的C:\xampp\htdocs\test\ftp_sync.php中有超过6个连接


我的代码导致错误:

 函数newStream($ i){
$ conId = ftp_connect($ this - > FTPServer的);

//使用用户名和密码登录
$ login_result = ftp_login($ conId,$ this-> ftpUsername,$ this-> ftpPassword); // line 58
// / home / content / 61/10367861 / html /

//在
上转变被动模式ftp_pasv($ conId,true);

$ this-> conIds [$ i] = $ conId;
$ this-> localFiles [$ i] ='';
$ this-> conStats [$ i] = FTP_FAILED; //初始值
}

有人可能知道这个错误信息是什么意思吗?

解决方案

这个错误是由于您的服务器限制最大每个用户的连接数/ IP地址。大多数人遇到的错误大多是这样的:


421 我不能接受超过 [0-9] + 连接作为同一用户

421 连接太多( [0-9 ] + )从这个IP


主要用于这种错误的FTP错误代码是 421 。这在 RFC 959(FTP)中定义为:


421 服务不可用,关闭控制连接。如果服务知道它必须关闭,这可能是任何命令的


您现在有两种可能解决此问题的解决方案:


  1. 减少程序连接的数量。
  2. 增加如果允许的最大值低于3,那么您应该先尝试更改配置文件文件在您的服务器上,因为大多数程序需要至少3个,有时2个。

    1。减少连接数量



    在程序中遇到问题时:某些FTP客户端允许用户更改连接数量设置。他们大多同时使用大约3个连接,其中2个用于提高性能,1个用于在用户执行其他任务时启用浏览。如果您在执行其他任务时不打扰浏览操作,则可以将数量减少到2或甚至1,而不会丢失任何重要功能。 ( FileZilla例如允许这样做。)



    在自己的代码中面对问题时:减少并发执行的任务数量。请检查您的代码是否正确关闭连接,以及是否引发错误。无论发生什么事,它总是应该被关闭。在PHP中,您可以使用 try-catch-blocks ,将用于关闭连接的代码放入 __destruct方法中。



    2。增加允许的连接数量



    这取决于您使用的是哪种FTP服务器。在 PureFTP (大多数UNIX系统使用)中,您需要更改 MaxClientsPerIP 设置在 /etc/pure-ftpd.conf 中。由默认配置文件或托管公司的大多数管理员设置的默认金额约为5-15。增加值,直到它符合您的需求。 请注意理论上说,位于大多数用户和FTP服务器之间的代理服务器可能会造成麻烦,因为大多数连接将使用相同的IP地址。






    在您的特殊情况下:由于 Mave 提到,你并没有关闭你的代码中的连接。这很容易导致多个连接处于活动状态,特别是如果您在短时间内多次运行代码。因此,在您的具体情况下,将添加 ftp_close($ conId); 修复问题。 (也可以使用try-catch-block。)


    I got the following error message:

    Warning: ftp_login(): I can't accept more than 6 connections as the same user in C:\xampp\htdocs\test\ftp_sync.php on line 58

    My code which causes the error:

    function newStream($i){
            $conId = ftp_connect($this->ftpServer);
    
            // login with username and password
            $login_result = ftp_login($conId, $this->ftpUsername, $this->ftpPassword);//line 58
            // /home/content/61/10367861/html/
    
            // turn passive mode on
            ftp_pasv($conId, true);
    
            $this->conIds[$i]=$conId;
            $this->localFiles[$i]='';
            $this->conStats[$i]=FTP_FAILED;//initial value
        }
    

    Does anyone probably know what this error message means?

    解决方案

    This error is thrown because your server restricts the maximum number of connections per user / IP address. The errors the most people encounter look mostly like this:

    421 I can't accept more than [0-9]+ connections as the same user

    421 Too many connections ([0-9]+) from this IP

    The FTP error code which is mostly used for this kind of error is 421. Which is defined in RFC 959 (FTP) as:

    421 Service not available, closing control connection. This may be a reply to any command if the service knows it must shut down.

    You have now exactly two possible solutions to solve this problem:

    1. Reduce the amount of connections made by your program.
    2. Increase the amount of allowed FTP connections to your server.

    If the allowed maximum is beneath 3, then you should first try to change the config file on your server, because the most programs need at least 3, sometimes 2.

    1. Reducing the amount of connections

    When facing the problem within a program: Some FTP clients allow the user to change the amount of used connections in the settings. They are mostly using about 3 connections at the same time, 2 to increase the performance, 1 to enable browsing while the user is performing other tasks. You can decrease the amount without losing any important functionality to 2 or even to 1, if you don't bother about browsing while performing other tasks. (FileZilla for example allow this.)

    When facing the problem within your own code: Reduce the amount of tasks which are performed concurrently. Check also if your code is closing the connections the right way, also when errors are thrown. It should always be closed, no matter what happens. In PHP you could use try-catch-blocks, inside a class you could put the code for closing the connection into the __destruct method.

    2. Increase the amount of allowed connections

    This depends on what kind of FTP server you are using. In PureFTP (used by the most UNIX systems) you need to change the MaxClientsPerIP setting in /etc/pure-ftpd.conf. The default amount set by the default configuration file or by the most administrators at hosting companies is somewhere about 5-15. Increase the value until it fits your needs. Be aware that theoretically a proxy server which is somewhere between the most users and the FTP server could cause trouble, because the most connection will then use the same IP address.


    In your special case: As Mave mentioned, you aren't closing the connections in your code. This could easily cause multiple connections being active, especially if you are running the code in a short period of time multiple times. So, in your specific case would adding ftp_close($conId); fix the problem. (Use also a try-catch-block.)

    这篇关于FTP连接太多,无法接受更多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆