<?php $link = mysql_connect('localhost', 'sms', 'sms');mysql_select_db('sms', $link);mysql_query("set names utf8");$sql = "SELECT phone,chang, msg, linkid, mo_time FROM tables '";$result = mysql_query($sql,$link);$array = array();while($row = mysql_fetch_array($result)){ $linkid = $row['phone'].date("YmdHis", strtotime($row['mo_time'])); $str = "SPNUM=".$row['chang']."&MOBILE=".$row['phone']."&CONTENT=".urlencode($row['msg'])."&MOTIME=".urlencode($row['mo_time'])."&LINKID=".$linkid; $url = "www.baidu.com?".$str; $array[] = $url; //var_dump($url); 这里使用curl访问,只能访问一条随后就中断了,只能在上面存放到数组中 /*$result = file_get_contents($url); var_dump($result);*/ /*$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);*/}//var_dump($array); //这里使用foreach循环执行curl命令foreach ($array as $url) { var_dump($url); $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); var_dump($result);}