使用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);
}
}
}