4

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.

enter image description here

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:

enter image description here

1
  • This is likely caused by a DNS issue. If you can connect to foo.richard.local, then start looking at how that's possible? How is the domain name being mapped to an IP address, and what is that IP address? Then consider that while you're able to connect, maybe the web server itself is unaware of that information. For example, if you're running a Linux VM, consider editing /etc/hosts.
    – jaswrks
    Nov 5, 2017 at 22:50

1 Answer 1

-1

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

1
  • I've been developing a plugin in my local dev environment that uses wp_remote_get(). I have allow_url_include = Off in my php.ini and it works without any problem. Jul 19, 2016 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.