Trying to check if REST API is active from a plugin, causes a time out

I have reported a details explanation of the issue in this post.

However, after some thinking, I was wondering if this could be caused by Local.

I’ve tried connecting via SSH and:

  • Ping to the domain: OK
  • wget to the discovery URL: OK

This means to me that Local might not be the issue. However, I still want to ask here if there is anything that Local could block and cause the request to timeout when done via PHP.

For the lazy ones, the problem is that domain.tld/wp-json works jusfinend when is done from a REST client, but not when done on PHP side with a $this->http->get( get_site_url() . '/wp-json', array( 'timeout' => 10) );: in this case, I get a timeout error, no matter how long I set that timeout.

As explained in the original thread, apparently, that was a mistake from my side: a bunch of checks done before running my code, made it work.

Glad you figured it out @misamee !

I haven’t done what you are describing within the context of the REST API’s classes.

For making external requests, I often will turn to the HTTP API: which helps to abstract out a lot of the low level cUrl type things. So for example, you could do something like:

$response = wp_remote_get( '' );
$body = wp_remote_retrieve_body( $response );
// do stuff

Hope that helps!