2016-04-14 39 views
0

我收到成千上万的错误日志,看起来像这样:FEOF()预计参数1是资源

$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); 
} 

已经通过呈三角问题,任何人,知道如何克服这个问题?

我已经用完整的代码更新了这个问题,同时我尝试执行已经给出的th消耗。

+0

$ handel有什么? –

+0

$ handle = fopen($ URL,'r',false,$ context); @ChetanAmeta – danrodrigues

+2

所以你的fopen()失败了 –

回答

1

你检查过fopen是否有效?

$handle = fopen($URL, 'r', false, $context); 
if ($handle === FALSE) { 
    echo 'Cannot open this url ' . $URL; 
    exit; 
} 
1

检查fopen

文档成功返回文件指针资源,或错误FALSE。

我觉得你的情况fopen返回falsefeof也返回false。这就是你无限循环的原因。

下面是feof文档报价

返回TRUE,如果文件指针是在EOF或发生错误(包括套接字超时);否则返回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是在做任何事情之前的资源。

相关问题