I have a WordPress instance on my development box with the WP REST API plugin installed. I am attempting to create my own plugin to use wp_remote_get() to communicate with my own custom PHP application on the same box.
I have set up my hosts file with the name of the custom PHP application. I have written a simple cURL request which is able to connect.
$curl = curl_init();
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_HEADER, 1 );
curl_setopt( $curl, CURLOPT_POST, false );
curl_setopt( $curl, CURLOPT_URL, "http://foo.richard.local/notify/$post_id" );
$curlData = curl_exec( $curl );
However when I try to use wp_remote_get() i’m getting a WP_Error
$response = wp_remote_get(
"http://foo.richard.local/notify/$post_id"
);
if ( is_wp_error( $response ) ) {
$errorResponse = $response->get_error_message();
}
Operation timed out after 5514 milliseconds with 0 bytes received
I have increased the timeout, but I’m still getting the same response.
I have installed the excellent Core Control plugin to verify the HTTP configuration settings.
The https_local_ssl_verify and https_ssl_verify filters have been set in my plugin.
The Core Control External HTTP Access Logger looks like this:
1 Answer
To make wp_remote_get()
work you need to check your php.ini
file. In your php.ini
file you need to set allow_url_include = On
, which by default is set as allow_url_include = Off
. Otherwise wp_remote_get()
will not work.
Reference: allow_url_include