How to run multiple Async HTTP requests in WordPress?

The (built-in) Requests class lets you call multiple requests simultaneously: Requests::request_multiple. <?php $requests = Requests::request_multiple([ [ ‘url’ => ‘https://www.mocky.io/v2/5acb821f2f00005300411631’, ‘type’ => ‘GET’, ‘headers’ => [ ‘Accept’ => ‘application/json’ ], ], [ ‘url’ => ‘https://www.mocky.io/v2/5acb821f2f00005300411631’, ‘type’ => ‘POST’, ‘headers’ => [ ‘Accept’ => ‘application/json’ ], ‘data’ => json_encode([ ‘text’ => ‘My POST Data’ ]) ], [ … Read more

Difference between wp_remote_post and wp_safe_remote_post

[*][**] So is there ever any other situation in which I would want to use wp_remote_post or should I always stick with wp_safe_remote_post? The two functions are exactly the same, except wp_safe_remote_post() sets the reject_unsafe_urls argument to true. That argument causes the URL to be passed through wp_http_validate_url() in WP_Http::request(). From that function, we see … Read more

Error timed out with succesfull wp_remote_post

After quite some time letting the error message bugging my screen, I figured out a way to solve this. Yes, it’s a timeout issue, and the codex didn’t help me much. So I tried another approach, by setting a filter; add_filter( ‘http_request_timeout’, ‘wp9838c_timeout_extend’ ); function wp9838c_timeout_extend( $time ) { // Default timeout is 5 return … Read more

Mutual Authentiction on HTTPS with WordPress HTTP API?

Re the WP HTTP API look for the sslverify and sslcertificates args in this docs page: https://developer.wordpress.org/reference/classes/wp_http/request/. sslverify defaults to true and sslcertificates accepts an absolute path to a certificate file. If you’re going to be doing a lot of lifting with this API (sounds like it for a real estate site), I would suggest … Read more

How to use the HTTP API with a Proxy?

The proxy settings work just like a regular HTTP requests but in this case obviously routed through a proxy. In terms of WordPress the API’s transport layers all support proxy connections(fsockopen, fopen, cURL, ). The things about proxy configurations are they come in several flavors and each setup is different so it makes answering this … Read more