'WAMP/Wordpress - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received

I have been stuck with this error for quite some time now. Earlier I got this error on godaddy and asked it over here. Now I'm getting it on hostinger shared hosting. So I migrated the production copy to local wamp server. I got the same error in the local copy as well.

Most of the people are suggesting it's a server error and stating the following rectification:

  1. Check if the server is running latest version of PHP and the cURL library. Update Wordpress and plugins.

     -  The local copy is running PHP 7.4.6 and the curl library packaged with it. Wordpress, plugins are up to date.
    
  2. Increase server memory limit

     - I tried many different combinations of settings. The current settings are:
         memory_limit = 256M
         upload_max_size = 64M
         post_max_size = 64M
         upload_max_filesize = 64M
         max_execution_time = 300
         max_input_time = 1000
    

    I tried increasing the memory limit and post max size but it does not solve the issue.

  3. It could be DNS related issue, switch to OpenDNS

    • I am getting it on localhost.
  4. Ask your host if there is some limitation with wp-cron, or if loopback is disabled.

  5. Ask your host if there a firewall or security modules (e.g. mod_security ) that could block the outgoing cURL requests.

Please suggest how should I check for 4 and 5 on wamp server. Is there something I'm missing in terms of php settings.

Error Source - http://jrventurefzellc.com/

Thank you for your time.



Solution 1:[1]

This issue tell you that the remote script was still running when your curl cut off the connection. You have to add a timeout option into your curl request! :)

In wordpress for example

$response = wp_remote_post( $url, array(
    'method'      => 'POST',
    'timeout'     => 45, // <--- this option
    'headers'     => array(),
    'body'        => array(
        'username' => 'bob',
        'password' => '1234xyz'
    )
);

Or PHP curl

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds

Solution 2:[2]

After a lot of playing around with php settings, this error was solved with the following PHP settings:

max_execution_time = 30
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
upload_max_size = 32M

I believe the problem was due to max_execution_time settings. Most of the guides suggested to increase it to 1000 along with increasing memory_limit, but that would lead to long load time. Tried it on a GoDaddy hosted website as well and it seems to work very well.

Update:

After a couple of days, this error had again shown up on the site. Later, through an inspection of function.php, I found that the issue was due to Wp-vcd malware. Removing the respective malware code and files solved it. WP-VCD affecting curl

Solution 3:[3]

You need to increase the timeout parameter. I was facing same issue and it's solved it like a magic:

$response = wp_remote_get( $url,
    array(
        'timeout'     => 60, // <-- this one increase to 120 or more
    )
);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ezequiel Fernandez
Solution 2
Solution 3 Mehdi Rahimi