5

我有一些代码可以从我们的开发服务器传输备份,它的随机行为似乎非常奇怪,并给出以下错误/输出:

Warning: ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106
ERR blahjob: Failed to get file: 2013-09-25_18-22-04-blahjob_dev18.tgz
PHP Warning:  ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106

Warning: ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106
ERR blahjob: Failed to get file: 2013-09-25_18-22-37-blahjob_dev19.tgz
PHP Warning:  ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106

Warning: ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106
ERR blahjob: Failed to get file: 2013-09-25_18-23-05-blahjob_dev5.tgz
PHP Warning:  ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106

Warning: ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106
ERR blahjob: Failed to get file: 2013-09-25_18-23-37-blahjob_dev33.tgz

我一点也不知道 delete 与 有什么关系ftp_get(),或者它为什么返回false并发出有关另一个操作成功的警告。谷歌在发现任何类似问题方面也无济于事。

有问题的代码:

// ftp connection established, file list acquired, yadda yadda
foreach( $targets as $target ) {
    $localfile = $backup_dir . $target;
    if( file_exists($localfile) ) {
        do_log($task['name'], "Local file ".$target." already exists, skipping.", 1);
        continue;
    }
    if( ! ftp_get($conn, $localfile, $target, FTP_BINARY) ) { // line 106
        do_log($task['name'], "Failed to get file: ".$target, 2);
    } else {
        do_log($task['name'], "Got file: ".$target);
        ftp_delete($conn, $target);
    }
}
4

1 回答 1

7

在我看来,你正在招致一个奇怪的 PHP 错误。

Delete operation successful.不是 PHP 错误消息,它是成功删除 (DELE) 命令的 FTP 服务器响应消息。

经过对 PHP 源代码的分析,我能找到的唯一解释是该ftp_get函数失败而没有从 FTP 服务器收到错误消息,因此它显示了上一个执行命令的 FTP 服务器响应,在这个具体情况,是删除命令。

PHP FTP 函数将 FTP 服务器响应文本存储在结构的inbuf 字段ftpbuf

typedef struct ftpbuf {
    ...
    char        inbuf[FTP_BUFSIZE]; /* last response text */
    ...
}

然后在ftp_get 函数中使用此类字段来显示警告消息:

if (!ftp_get(ftp, outstream, remote, xtype, resumepos TSRMLS_CC)) {
    php_stream_close(outstream);
    VCWD_UNLINK(local);
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    RETURN_FALSE;
}

ftp->inbuf字段由ftp_getresp fnc编写,但可能是由于某种模糊的原因,低级别ftp_get 函数在未调用该ftp_getresp函数的情况下失败,因此显示了误导性错误消息。
也许 FTP 服务器错误日志可以提供一些关于真正问题的线索,但如果没有更多信息,很难说出您遇到此问题的原因,甚至提出解决方法。

我唯一的建议是针对不同的 FTP 服务器测试您的代码(如果可能),然后最终将您的 PHP 升级到更新版本。

于 2013-10-04T10:06:11.280 回答