PHP curl在所有情况下都不返回数据
我正在实现一个基本的IMAP客户机,它支持多个连接库——php_IMAP、套接字和curl php_imap和sockets方法工作正常。curl方法适用于除FETCH之外的所有命令,因此我知道我的代码中没有错误。如果我通过套接字发送相同的命令,它就会工作,因此我也知道我的命令中没有错误。此外,如果启用详细输出,则可以看到消息实际上已发送回PHP curl在所有情况下都不返回数据,php,curl,imap,Php,Curl,Imap,我正在实现一个基本的IMAP客户机,它支持多个连接库——php_IMAP、套接字和curl php_imap和sockets方法工作正常。curl方法适用于除FETCH之外的所有命令,因此我知道我的代码中没有错误。如果我通过套接字发送相同的命令,它就会工作,因此我也知道我的命令中没有错误。此外,如果启用详细输出,则可以看到消息实际上已发送回 function write($command) { $url = ($this->type == 'imap' ? 'imap' :
function write($command) {
$url = ($this->type == 'imap' ? 'imap' : 'pop3') . ($this->secure ? 's' : '') . '://' . $this->host . '/INBOX';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $this->port);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
$fp = tmpfile();
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $command);
$res = curl_exec($ch);
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo($verboseLog);
fclose($verbose);
return $res;
}
这项工作:
write('STATUS "INBOX" (MESSAGES)');
返回空字符串(UID有效-与套接字一起使用)
curl-IMAP实现中是否存在bug?我已经用curl7.30.0和7.35.0进行了测试,如果您使用apachehttpd,请尝试重新启动它。
它用cURL请求中的空响应解决了我的问题。如果您需要$res的响应
$res = curl_exec($ch);
你必须定下来
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
否则curl会将其发送到stdout
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);