PHP Twilio应用程序 - 包括SMS文件中断Foreach循环

问题描述:

我无法弄清楚这一点,所以我希望你能伸出援手。PHP Twilio应用程序 - 包括SMS文件中断Foreach循环

我正在创建一个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"; 
    } 

?> 

我认为问题是,你正在做内部的一个需要循环。在第二次你需要它的时候,在twilio library中定义了对象,这些类再次被定义,并且引发错误。

如果您设置了error_reporting(E_ALL),那么您将在输出中看到该效果的异常。

我会将其更改为require_once或将其移出for循环。

我希望有帮助。

+0

谢谢,修复它。 –