最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

remote - Set timeout on wp_remote_post()

programmeradmin1浏览0评论

I am trying to use wp_remote_post() like this:

wp_remote_post( $url, array( 'blocking' => false, 'timeout' => 0.1 ) );

The problem is that it seems to always force the timeout to 1s.
I don't even want to wait for 1s, I just want the remote post to start and immediately go back to my the calling function. ( I have also tried setting timeout => 0 but it always takes 1s to return.)

How can I skip this minimum of 1s?

I am trying to use wp_remote_post() like this:

wp_remote_post( $url, array( 'blocking' => false, 'timeout' => 0.1 ) );

The problem is that it seems to always force the timeout to 1s.
I don't even want to wait for 1s, I just want the remote post to start and immediately go back to my the calling function. ( I have also tried setting timeout => 0 but it always takes 1s to return.)

How can I skip this minimum of 1s?

Share Improve this question asked Sep 17, 2017 at 10:36 l_nxyl_nxy 591 silver badge6 bronze badges 1
  • try, like in wp_cron, 'timeout' => 0.01, – mmm Commented Sep 17, 2017 at 12:16
Add a comment  | 

2 Answers 2

Reset to default 1

For cURL, a minimum of 1 second applies, as DNS resolution operates at second-resolution only. See more in wp-includes/class-request.php function request()

The timeout is the maximal not minimal time the functions waits for an answer. So, if the answers comes before the timeout, the function returns the value.

The argument 'timeout' allows for setting the time in seconds, before the connection is dropped and an error is returned.

source: https://codex.wordpress/HTTP_API#Other_Arguments

Also: The timeout has to be an integer, not a float.

发布评论

评论列表(0)

  1. 暂无评论