Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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/Curl-Loop&;后缓冲区未清除_Php_Html_Loops_Curl_Buffer - Fatal编程技术网

PHP/Curl-Loop&;后缓冲区未清除

PHP/Curl-Loop&;后缓冲区未清除,php,html,loops,curl,buffer,Php,Html,Loops,Curl,Buffer,我使用cUrl发布到一个web页面(不是本地页面),然后返回html 我需要多次这样做,因此cUrl代码处于while循环中。奇怪的是:它在第一次运行时就像预期的那样,但似乎没有在以后每次都清除POST缓冲区。(我确实关闭了_curl($ch)。通过POST传递的所有数据都是正确的。) 例如,其中一个文本字段应该是(第一次是)pass“ANY”。但第二次是通过“任何,任何” 此问题存在于未清除的后期缓冲区中,我是否正确?如何修复它? 抱歉:这是代码的缩短版本 $someResults = my

我使用cUrl发布到一个web页面(不是本地页面),然后返回html

我需要多次这样做,因此cUrl代码处于while循环中。奇怪的是:它在第一次运行时就像预期的那样,但似乎没有在以后每次都清除POST缓冲区。(我确实关闭了_curl($ch)。通过POST传递的所有数据都是正确的。)

例如,其中一个文本字段应该是(第一次是)pass“ANY”。但第二次是通过“任何,任何”

此问题存在于未清除的后期缓冲区中,我是否正确?如何修复它?


抱歉:这是代码的缩短版本

$someResults = mysql_query($someSQL);

while($record = mysql_fetch_array($alertResults)){
    $url = "http://something.com/searchResults.asp";
    $someV = "Hi";

    $fields = array(
        //date to post.
    );     

    foreach($fields as $key=>$value){ 
        $fields_string .= $key .'='. $value . '&'; 
    }
    rtrim($fields_string,'&');
    $ch = curl_init();
    $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
    curl_setopt($ch,CURLOPT_USERAGENT, $userAgent);
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
    ob_start(); 
    $html = curl_exec($ch);
    curl_close($ch);

    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    $xpath = new DOMXPath($dom);
    $resultTable = $xpath->evaluate("/html/body//table"); 
}
当我这样做时,第一次通过循环$resultable时,其中有60个项。但每次之后(使用相同的url),它都有0个项目。我很确定这是因为POST缓冲区没有被清除,东西会被上传到以前的POST数据上


如何在每次循环中清除POST数据?

您似乎忘记了重置
$fields\u string
,请尝试以下操作

...
curl_close($ch);
unset($fields_string);
...

您似乎忘记了重置
$fields\u string
,请尝试以下操作

...
curl_close($ch);
unset($fields_string);
...

您可以发布循环/卷曲的代码吗?正如@Oli所说,如果我们要评估问题是什么,我们真的需要查看代码。:-)添加它!非常感谢您的帮助。您能发布循环/卷曲的代码吗?正如@Oli所说,如果我们要评估问题所在,我们确实需要查看代码。:-)添加它!非常感谢您的帮助。