2013-03-28 59 views
2

當長輪詢天青隊列存儲與天青-SDK換PHP,如果我的請求是超過30秒開,所述庫與此錯誤模具:輪詢天青隊列返回管道中斷

PHP Notice: fwrite(): send of 277 bytes failed with errno=32 Broken pipe in ..../vendor/pear-pear.php.net/HTTP_Request2/HTTP/Request2/SocketWrapper.php on line 188 

如果我將睡眠函數設置爲30秒,那麼所有事情都會很好,但是我正在做很多我不需要的請求。

我的工人代碼:

use WindowsAzure\Common\ServicesBuilder; 
use WindowsAzure\Common\ServiceException; 

Class Worker_Task { 

    public $queueRestProxy; 

    public $servicesBuilder; 

    public $connectionString; 

    public function __construct() { 
     $this->connectionString = Config::get('azure.connection_string'); 
     $this->servicesBuilder = ServicesBuilder::getInstance(); 
     $this->queueRestProxy = $this->servicesBuilder->createQueueService($this->connectionString); 
    } 
    public function emails() { 

     $this->write('Processing mails...'); 

     while(true) { 

      $this->queueRestProxy = $this->servicesBuilder->createQueueService($this->connectionString); 

      // Get message. 
      $listMessagesResult = $this->queueRestProxy->listMessages("emails"); 
      $messages = $listMessagesResult->getQueueMessages(); 

      foreach($messages as $message) { 

       // Process Message 
       $content = json_decode($message->getMessageText()); 

       // Dispatch Email 

       // Delete Job 
       $this->deleteJob('emails', $message->getMessageId(), $message->getPopReceipt()); 
      } 

      sleep(30); 
     } 
    } 

} 
+0

什麼是/SocketWrapper.php的180-200行? – Abela 2013-04-07 03:05:02

+0

@Yhanhannan他們正在使用PEAR軟件包(HTTP_Request2)。我用你所要求的幾行創建了一個要點:https://gist.github.com/fedeisas/5331164#file-socketwrapper-php-L175。 Thanks1 – fedeisas 2013-04-07 16:21:29

回答

1

這看起來像是過載或超時問題。 PHP庫無法寫入Azure套接字。可能你超過了無限循環的Azure負載限制while(true) { ... }

不要在每個循環創建queueService,因爲您無限地關閉和打開pear套接字。

嘗試移動線:

$this->queueRestProxy = $this->servicesBuilder->createQueueService($this->connectionString); 

while(true) {

$this->write('Processing mails...'); 
$this->queueRestProxy = $this->servicesBuilder->createQueueService($this->connectionString);  
while(true) { 
     // Get message. 

如果不能再幫可能azure-sdk-for-php庫錯誤地使用套接字機制 - 在https://github.com/WindowsAzure/azure-sdk-for-php創造新的問題,或者使用此方法:AzurePHP - Polling an Azure Queue

+0

您提到的那一行僅用於測試用途。我試圖「重新打開」套接字......問題在於,如果我在30秒內未提出請求,套接字就會死亡。這就是我試圖重新生成套接字的原因。 – fedeisas 2013-04-11 21:25:53

+0

好的,所以它是'azure-sdk-for-php'的問題,如果需要,QueueService應該在'listMessages'上重新打開套接字。 – rogal111 2013-04-12 15:01:17