简体   繁体   English

PHP ftp_get挂起

[英]PHP ftp_get hangs

I am trying to download a file using FTP in PHP CLI. 我正在尝试在PHP CLI中使用FTP下载文件。 I have no access to the server where I'm downloading from. 我无权访问要从中下载的服务器。

Here's some information about my system. 这是有关我的系统的一些信息。

$ php -v

PHP 5.5.12 (cli) (built: Aug 16 2014 11:36:51) (DEBUG)

$ cat /etc/*-release

NAME="Red Hat Enterprise Linux Server"
VERSION="7.0 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="7.0"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.0 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.0:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.0
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION=7.0
Red Hat Enterprise Linux Server release 7.0 (Maipo)
Red Hat Enterprise Linux Server release 7.0 (Maipo)

Here's the code. 这是代码。

$ftpconn = ftp_connect(FTP_HOST);
ftp_set_option($ftpconn, FTP_TIMEOUT_SEC, 86000);
$ftplogin = ftp_login($ftpconn, FTP_USER, FTP_PASS);
ftp_pasv($ftpconn, true);
$list = ftp_nlist($ftpconn, FTP_PATH);
foreach($list as $file){
    ftp_get($ftpconn, DOWNLOAD_PATH . DIRECTORY_SEPARATOR . $file, $file, FTP_BINARY)
}

When the script hits ftp_get the file is created with the proper name, but then it hangs for the amount of time specified in ftp_set_option . 当脚本命中ftp_get ,将使用适当的名称创建文件,但是该文件将挂起ftp_set_option指定的时间。 PHP never writes anything to the file. PHP从不向文件写入任何内容。

I have set 777 permission for the root folder where it's located recursively. 我已经为递归设置的根文件夹设置了777权限。 I'm also running PHP CLI as root. 我也以root用户身份运行PHP CLI。

sudo php /path/to/php/file.php

Is this a problem with PHP being unable to write to the file? 这是PHP无法写入文件的问题吗? Why is it not throwing any errors? 为什么不抛出任何错误? When the timeout is reached, the ftp_get function simply returns false. 当达到超时时, ftp_get函数仅返回false。

Help would be greatly appreciated. 帮助将不胜感激。

The problem was caused by Amazon AWS instance, certain instances changed the MTU of the network interface. 该问题是由Amazon AWS实例引起的,某些实例更改了网络接口的MTU。

The solution was as simple as giving the following command: 解决方案非常简单,只需给出以下命令:

sudo ifconfig eth0 mtu 1500

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM