首頁  >  文章  >  php教程  >  while循环中不支持循环使用curl

while循环中不支持循环使用curl

WBOY
WBOY原創
2016-06-13 11:30:441425瀏覽

<?<span php 
</span><span $link</span> = <span mysql_connect</span>('localhost', 'sms', 'sms'<span );
</span><span mysql_select_db</span>('sms', <span $link</span><span );
</span><span mysql_query</span>("set names utf8"<span );
</span><span $sql</span> = "<span 
SELECT phone,chang, msg, linkid, mo_time FROM tables '</span>"<span ;

</span><span $result</span> = <span mysql_query</span>(<span $sql</span>,<span $link</span><span );
</span><span $array</span> = <span array</span><span ();
</span><span while</span>(<span $row</span> = <span mysql_fetch_array</span>(<span $result</span><span )){


    </span><span $linkid</span> = <span $row</span>['phone'].<span date</span>("YmdHis", <span strtotime</span>(<span $row</span>['mo_time'<span ]));
    </span><span $str</span> = "SPNUM=".<span $row</span>['chang']."&MOBILE=".<span $row</span>['phone']."&CONTENT=".<span urlencode</span>(<span $row</span>['msg'])."&MOTIME=".<span urlencode</span>(<span $row</span>['mo_time'])."&LINKID=".<span $linkid</span><span ;

    </span><span $url</span> = "www.baidu.com?".<span $str</span><span ; 
    </span><span $array</span>[] = <span $url</span><span ;
    </span><span //</span><span var_dump($url); 这里使用curl访问,只能访问一条随后就中断了,只能在上面存放到数组中</span>
    <span /*</span><span $result = file_get_contents($url);
    var_dump($result);</span><span */</span>
    <span /*</span><span $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
     // 4. 释放curl句柄
      curl_close($ch);</span><span */</span><span 
}
</span><span //</span><span var_dump($array); 
//这里使用foreach循环执行curl命令</span>
<span foreach</span> (<span $array</span> <span as</span> <span $url</span><span ) {
    </span><span var_dump</span>(<span $url</span><span );
    </span><span $ch</span> = curl_init(<span $url</span><span );
    curl_setopt(</span><span $ch</span>, CURLOPT_TIMEOUT, 40<span );
    curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, <span true</span><span );
    </span><span $result</span> = curl_exec(<span $ch</span><span );
     </span><span //</span><span  4. 释放curl句柄</span>
      curl_close(<span $ch</span><span );
      </span><span var_dump</span>(<span $result</span><span );
}</span>

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn