我得到了数以千计的错误日志,如下所示:
$xml = "<requisicao-boleto>
<website>
<n_website>{$n_website}</n_website>
<password>{$password}</password>
</website>
<sacado>
<name>{$name}</name>
{$user_code}
<address>
<street>{$street}</street>
<complement>{$complement}</complement>
<number>{$number}</number>
<district>{$district}</district>
<state_province>{$state_province}</state_province>
<city>{$city}</city>
<postcode>{$postcode}</postcode>
<country>{$country}</country>
</address>
</sacado>
<dados_boleto>
<product>{$product}</product>
<reference>{$uid}</reference>
<value>{$value}</value>
</dados_boleto>
</requisicao-boleto>";
$xml = preg_replace('/\s(?=\s)/', '', $xml);
$xml = "xml=" . $xml;
$n = strlen($xml);
$opts = array(
'http' => array(
'method' => "POST",
'header' => "User-Agent: My Own Http Client\r\n" .
"Content-length: " . $n . "\r\n",
'content' => $xml
)
);
$context = stream_context_create($opts);
$handle = fopen($URL, 'r', false, $context);
$conteudo = '';
while (!feof($handle)) {
$conteudo .= fread($handle, 1024);
}代码是:
while (!feof($handle)) {
$conteudo .= fread($handle, 1024);
}有没有人经历过类似的问题,并知道如何克服这个问题?
我已经用完整的代码更新了这个问题,同时我试图实现已经给出的建议。
发布于 2016-04-14 20:03:01
你检查了fopen是否正常工作了吗?
$handle = fopen($URL, 'r', false, $context);
if ( $handle === FALSE ) {
echo 'Cannot open this url ' . $URL;
exit;
}发布于 2016-04-14 20:05:36
查看有关fopen的文档
如果成功,
将返回文件指针资源;如果失败,则返回FALSE。
我认为在您的例子中,fopen返回了false,feof也返回了false。这就是为什么你会得到无限循环。
以下是feof文档中的引用
如果文件指针在EOF或发生错误(包括套接字超时),则
返回TRUE;否则返回FALSE。
您的示例如下所示
php > var_dump(feof(false));
PHP Warning: feof() expects parameter 1 to be resource, boolean given in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. feof() php shell code:1
bool(false)
php > 在执行其他操作之前,您需要检查$handle是否是一个资源。
https://stackoverflow.com/questions/36622296
复制相似问题