2

使用azure-sdk-for-php长轮询 Azure 队列存储时,如果我的请求相隔超过 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);
        }
    }

}
4

1 回答 1

1

这看起来像过载或超时问题。PHP 库无法写入 Azure 套接字。可能您使用无限循环超出了 Azure 负载限制while(true) { ... }

不要queueService在每个循环中创建,因为您会无限关闭和打开梨形套接字。

尝试移动线:

$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

于 2013-04-10T15:20:52.140 回答