下面的代码只是向我的脚本发送一个变量,但它正常运行循环。我将不胜感激。谢谢。
<?php
$result = mysql_query("SELECT * FROM users WHERE id =$id");
while($row = mysql_fetch_assoc($result)){
//$user_phone = $row['phone'];
$phone = $row['email'];
$email = $row['phone'];
$url = 'http://example.com/request.php?phone='.$phone.'&email='.$email.'';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => '5'
));
$resp = curl_exec($curl);
curl_close($curl);
}
?>
答案 0 :(得分:2)
我想尝试将curl语句与循环分开。
<?php
$result = mysql_query("SELECT * FROM users WHERE id =$id");
while($row = mysql_fetch_assoc($result)){
//$user_phone = $row['phone'];
$phone = $row['email'];
$email = $row['phone'];
$url = 'http://example.com/request.php?phone='.$phone.'&email='.$email.'';
call_curl($url);
}
?>
function call_curl($url){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => '5'
));
$resp = curl_exec($curl);
curl_close($curl);
}