2011-07-13 35 views
2

我無法弄清楚這一點,所以我希望你能伸出援手。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"; 
    } 

?> 

回答

4

我認爲問題是,你正在做內部的一個需要循環。在第二次你需要它的時候,在twilio library中定義了對象,這些類再次被定義,並且引發錯誤。

如果您設置了error_reporting(E_ALL),那麼您將在輸出中看到該效果的異常。

我會將其更改爲require_once或將其移出for循環。

我希望有幫助。

+0

謝謝,修復它。 –