我想不明白,所以我希望你能伸出援助之手。
我正在创建一个twilio应用程序,并且我将整个文件包含在foreach循环中。但是它总是打破我的循环,并且在运行后不会继续。
它工作得很好,但是包含在里面的foreach在它运行后不会继续。
任何想法?
谢谢,尼克
<?php
//shorten the URL
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$ebay_url);
// Include the PHP TwilioRest library
require "twilio/twilio.php";
// Twilio REST API version
$ApiVersion = "2010-04-01";
// Set our AccountSid and AuthToken
$AccountSid = "removed";
$AuthToken = "removed";
// Instantiate a new Twilio Rest Client
$client = new TwilioRestClient($AccountSid, $AuthToken);
// make an associative array of server admins
$people = array(
"removed"=>"Nick",
//"4158675310"=>"Helen",
//"4158675311"=>"Virgil",
);
// Iterate over all our server admins
foreach ($people as $number => $name) {
// Send a new outgoinging SMS by POST'ing to the SMS resource */
// YYY-YYY-YYYY must be a Twilio validated phone number
$response = $client->request("/$ApiVersion/Accounts/$AccountSid/SMS/Messages",
"POST", array(
"To" => $number,
"From" => 'removed',
"Body" => 'Alert! '.$title.' found for '. $price. '. View the item here: '.$tinyurl,
));
if($response->IsError)
echo "Error: {$response->ErrorMessage}n";
else
echo "Sent message to: {$response->ResponseXml->SMSMessage->To}n";
}
?>
我认为问题是你在for循环中做了一个require。twilio库中定义了一些对象,所以当你第二次需要它时,这些类会被重新定义,这会抛出一个错误。
如果你设置了error_reporting(E_ALL),那么你会在输出中看到一个异常。
我要么把它改成require_once,要么把它移出for循环。