简体   繁体   English

使用 Google Cloud PubSub Client Library for php 时,我们如何最大限度地减少超时?

[英]How do we minimise the timeout when using Google Cloud PubSub Client Library for php?

We have been getting these exceptions from Google this evening:今晚我们从谷歌那里得到了这些例外:

Google\\Cloud\\Core\\Exception\\ServiceException: cURL error 56: OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html ) Google\\Cloud\\Core\\Exception\\ServiceException:cURL 错误 56:OpenSSL SSL_read:SSL_ERROR_SYSCALL,errno 104(参见http://curl.haxx.se/libcurl/c/libcurl-errors.html

Google\\Cloud\\Core\\Exception\\ServiceException(code: 0): cURL error 7: Failed to connect to oauth2.googleapis.com port 443: Connection timed out (see http://curl.haxx.se/libcurl/c/libcurl-errors.html ) Google\\Cloud\\Core\\Exception\\ServiceException(代码:0):cURL 错误 7:无法连接到 oauth2.googleapis.com 端口 443:连接超时(请参阅http://curl.haxx.se/libcurl/c/ libcurl-errors.html )

Google\\Cloud\\Core\\Exception\\ServiceException(code: 0): cURL error 28: Operation timed out after 2001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html ) Google\\Cloud\\Core\\Exception\\ServiceException(代码:0):cURL 错误 28:操作在 2001 毫秒后超时,收到 0 个字节(参见http://curl.haxx.se/libcurl/c/libcurl-errors.html )

We can handle the exceptions fine, but there is a significant timeout between the connection initiation and the exception occurring.我们可以很好地处理异常,但是在连接启动和异常发生之间存在明显的超时。 This means our server hangs for a long period of time as a request is initiated to Google, waits for connection to be properly created, fails, and then continues.这意味着我们的服务器在向 Google 发起请求时会长时间挂起,等待连接正确创建,失败,然后继续。 This means our requests take a ridiculous amount of time (~20 seconds - 3 minutes approximately) instead of milliseconds.这意味着我们的请求花费了大量的时间(大约 20 秒 - 大约 3 分钟)而不是毫秒。

So:所以:

  • How can we determine what the root cause of this problem is?我们如何确定这个问题的根本原因是什么? I'm assuming it's a Google related service issue, but their Google Console is clear我假设这是与 Google 相关的服务问题,但他们的 Google Console 很清楚
  • How can we set a timeout to be significantly shorter so that it doesn't cause long delays, particularly of importance with user facing requests.我们如何将超时设置为显着更短,以便它不会导致长时间延迟,这对于面向用户的请求尤其重要。

We're using the PHP PubSubClient, specifically only the publish method at the moment.我们正在使用 PHP PubSubClient,特别是目前仅使用publish方法。

I believe this can be fixed by the following:我相信这可以通过以下方式解决:

$pubsub->publish(
    [
        'data'       => $data,
        'attributes' => $attributes,
    ],
    [

        'requestTimeout' => 2 // Set your own value here (in seconds)
    ]
);

This seems to be translated into a Guzzle option under the hood.这似乎被转化为引擎盖下的 Guzzle 选项。

See \\Google\\Cloud\\Core\\RestTrait::send for more info查看\\Google\\Cloud\\Core\\RestTrait::send了解更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为google api php客户端库设置超时 - How to set timeout for google api php client library 如何使用Google_Client库将文件上传到Google云存储中的目录 - how do i upload a file to a directory in google cloud storage using Google_Client library 如何使用PHP客户端库从Google Cloud检索文件夹文件? - How to retrieve folder files from Google Cloud using PHP client library? Google Cloud Client Library PHP安装失败 - Google Cloud Client Library PHP Install Failed php 将消息发布到谷歌云 pubsub - php publish message to google cloud pubsub 如何使用Google_Service_Pubsub_Topics_Resource(PHP)向Google Pubsub消息添加属性? - How to add attributes to Google Pubsub message using Google_Service_Pubsub_Topics_Resource (PHP)? 如何在PHP中包含Google客户端库的路径 - How do I include a path of google client library in php Google - “尽快迁移到新的 Google 身份服务库”。 我们是否需要删除对 google-api-php-client 的使用? - Google - "Migrate to the new Google Identity Services library as soon as possible". Do we need to remove our use of google-api-php-client? Google Cloud Vision客户端库(PHP)图像标签-结果数量? - Google Cloud Vision Client Library (PHP) Image Labels - Number of results? Google Cloud PHP Curl超时 - Google Cloud PHP Curl timeout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM