2017-08-25 71 views
1

我正在使用Twilio PHP API向我的客戶發送大量短信。
問題是,我只能像發送短信80st,然後我得到了一個服務器錯誤:503嘗試使用Twilio發送短信時出錯

Failed to load resource: the server responded with a status of 503 (Backend fetch failed)

嗯,我想這可能是錯誤。
因爲我沒有成功回聲echo "Sent message to $name和twilio短信日誌,我只能看到80發送了200條短信。

什麼會導致此錯誤?

foreach ($usrs as $number => $name) { 
    try{ 
     $sms = $client->account->messages->create(

      // the number we are sending to - Any phone number 
      $number, 

      array(
       // Step 6: Change the 'From' number below to be a valid Twilio number 
       'from' => "xxxxxxxxxxx", 

       // the sms body 
       'body' => "Hey $name. $text" 
      ) 
     ); 

     // Display a confirmation message on the screen 
     echo "Sent message to $name <br>"; 
    } 
    catch (TwilioException $e) { 
     die($e->getCode() . ' : ' . $e->getMessage()); 
    } 
} 
+1

我認爲它是因爲你可以每秒發送特定的消息。 延遲了一些短信和[檢查鏈接](https://support.twilio.com/hc/en-us/articles/115002943027-Understanding-Twilio-Rate-Limits-and-Message-Queues) –

回答

1

Twilio開發者傳道這裏。

Twilio has a limit of 100 concurrent API requests and will only send 1 message a second。正如Ahmed在評論中所建議的那樣,如果您發送超過100條消息,我建議您在調用API之間添加一個延遲時間。

編輯

sleep(1)添加針對每個消息。這會在發送每封郵件後使頁面延遲一秒。

foreach ($usrs as $number => $name) { 
    try{ 
     $sms = $client->account->messages->create(

      // the number we are sending to - Any phone number 
      $number, 

      array(
       // Step 6: Change the 'From' number below to be a valid Twilio number 
       'from' => "xxxxxxxxxxx", 

       // the sms body 
       'body' => "Hey $name. $text" 
      ) 
     ); 

     // Display a confirmation message on the screen 
     echo "Sent message to $name <br>"; 

     sleep(1); 
    } 
    catch (TwilioException $e) { 
     die($e->getCode() . ' : ' . $e->getMessage()); 
    } 
} 
+0

謝謝。我會測試這個。你可以給我一個例子嗎?我還以爲我應該在循環中逐一回答成功迴應..但是當頁面失敗時,循環停止我沒有看到一個成功的文本。爲什麼是這樣? –

+0

你是否向HTML頁面回覆成功消息? – philnash

+0

我的問題中顯示的腳本位於php文件中。在使用try-catch函數來清理壞的nr之前,我有回聲工作。 –