Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP获取FTP超时错误&;共点火器_Php_Codeigniter_Ftp - Fatal编程技术网

使用PHP获取FTP超时错误&;共点火器

使用PHP获取FTP超时错误&;共点火器,php,codeigniter,ftp,Php,Codeigniter,Ftp,我正在尝试使用PHP和Codeigniter通过FTP发送文件。实际上,我没有使用Codeigniter FTP类,因为它不满足我的需要,所以它是本机PHP 基本上,我需要的是脚本在发送的文件超时时执行操作。目前我的代码是: // connect to the ftp server $connection = ftp_connect($item_server); // login to the ftp account $login = ftp_login($connection, $item_

我正在尝试使用PHP和Codeigniter通过FTP发送文件。实际上,我没有使用Codeigniter FTP类,因为它不满足我的需要,所以它是本机PHP

基本上,我需要的是脚本在发送的文件超时时执行操作。目前我的代码是:

// connect to the ftp server
$connection = ftp_connect($item_server);

// login to the ftp account
$login = ftp_login($connection, $item_username, $item_password);

// if the connection or account login failed, change status to failed
if (!$connection || !$login) 
    { 
        // do the connection failed action here
    }
else
    {

// set the destination for the file to be uploaded to
$destination = "./".$item_directory.$item_filename;

// set the source file to be sent
$source = "./assets/photos/highres/".$item_filename;

// upload the file to the ftp server
$upload = ftp_put($connection, $destination, $source, FTP_BINARY);

// if the upload failed, change the status to failed
if (!$upload) 
    {
        // do the file upload failed action here
    }
// fi the upload succeeded, change the status to sent and close the ftp connection
else 
{
    ftp_close($connection);
    // update the item's status as 'sent'
// do the completed action here
    }

}
因此,脚本基本上连接到服务器并尝试将文件放入。如果无法建立连接或无法插入文件,它当前会执行操作。但我认为它只是坐在那里,没有反应。我需要一个对所有事情的响应,因为它是在一个自动脚本中运行的,用户知道发生了什么的唯一方法是如果脚本告诉他们

如果服务器超时,如何获得响应

非常感谢您的帮助:)

如果您阅读,请忽略默认为90秒的超时值

您可以将此值设置为更可接受的值,并单独验证连接,而不是同时验证连接和登录

// connect to the ftp server and timeout after 15 seconds if connection can't be established
$connection = ftp_connect($item_server, 21, 15);
if( ! $connection )
{
    exit('A connection could not be established');  
}

// login to the ftp account
if( ! ftp_login($connection, $item_username, $item_password) )
{
    exit('A connection was established, but the credientials seems to be wrong');   
}
请注意,
ftp\u login()
将在登录凭据错误时抛出警告,因此您可以用另一种方式处理(错误处理或干脆取消警告)