gpt4 book ai didi

php - 轮询 Azure 队列返回损坏的管道

转载 作者:行者123 更新时间:2023-12-03 11:54:20 26 4
gpt4 key购买 nike

使用 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

如果我将 sleep 功能设置为 30 秒,一切都会很好,但我会发出很多我不需要的请求。

我的 worker 代码:

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

}

最佳答案

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

不要在每个循环中创建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

关于php - 轮询 Azure 队列返回损坏的管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15672282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com