curl_init() 有关问题

WBOY
Release: 2016-06-13 11:53:21
Original
805 people have browsed it

curl_init() 问题
我用curl_init() 传递xml文档
--
$sql=”select aa from bb ”;
$n=$DB->ExecSQL( $sql );
while( $DB->Fetch() ) {
$md5 = md5($SRC."&key=6c3d80558fec2784b20a95863dca9458");
$WEB = new WEB_SERVICE( $HOST, 80, $URL, "POST" );
$WEB->addPara( "para_xml"    , $SRC );
$WEB->addPara( "MD5Data"     , $md5 );
$WEB->addPara( "customersid" , "10058" );
$ret = $WEB->run();
$WEB->close();  }

Run()函数大概的写法
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, "http://".$this->IP.$this->URL);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $this->PARAMETER );
         $ret = curl_exec($ch);
         curl_close ($ch);

问题 :sql语句查出1000笔数据 ,但可能有10笔不成功。 如果把这不成功的10笔数据再次传送,又传送成功了。
我发现问题是循环中反复连接页面时,有时候会连接不成功,即$ret = $WEB->run(); 返回空值。所以没有传送成功
请问这样的问题应该如何解决??
要每次传数据后加个sleep() 来控制下重复连接触发的时间吗?

------解决方案--------------------
可以用sleep试下。
------解决方案--------------------
你可以通过 curl_getinfo 观察是否传递成功
你也可以汇集所有的数据,一次性传递
你还可以以多道方式(curl_multi)进行传递
------解决方案--------------------
应该记录状态吧,除了完成的都重新提交

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!