1

I am using localhost and working on a wordpress plugin, I try to get and post data with wp_remote_get and wp_remote_post,i installed lmfwc and i create a rest-api-key, as you can see i used consumer key and consumer secret in url, to get licenses and I have been able to get all the data, I also set all wp remote get and post args, but I got WP ERROR, cURL error 28.

1-Dashboardfile

     $endpoint = add_query_arg(
                array(
                    'code' => $purchase,
                ),
                self::$api
        );
        
        $options = [
                'body'        => wp_json_encode( array(
                    'code' => $purchase,
                ) ),
                'method'  => 'POST',
                'headers'     => [
                    'Content-Type' => 'application/json',
                ],
                'timeout'     => 10,
                'redirection' => 5,
                'blocking'    => true,
                'httpversion' => '1.0',
                'sslverify'   => false,
        ];
        
        $remote_test = wp_remote_post( $endpoint, $options );

2-Verificationfile

$baseUrl = get_site_url(); 
$args = array(
    'timeout' => 10,
    "sslverify" => false,
);

$licenses_url = $baseUrl . '/wp-json/lmfwc/v2/licenses?consumer_key=ck_a50c1db92c5e5aa63d4&consumer_secret=cs_2b3e19c';
$response = wp_remote_get( $licenses_url, $args );

Error

WP_Error Object
(
    [errors] => Array
        (
            [http_request_failed] => Array
                (
                    [0] => cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received
                )
        )

    [error_data] => Array
        (
        )

    [additional_data:protected] => Array
        (
        )
)

1 Answer 1

1

The cURL error 28 you are encountering indicates that the cURL request used by wp_remote_get and wp_remote_post is timing out. In your case, it's timing out after 10 seconds (10001 milliseconds) without receiving any response from the server.

Here are a few steps you can take to troubleshoot and potentially resolve this issue:

1. Increase Timeout: You can try increasing the timeout value for your requests. Sometimes, requests can take longer to process, especially if you're working on localhost or dealing with a remote server with slower response times. You can set a higher timeout value like 30 seconds:

$args = array(
    'timeout' => 30, // Set a higher timeout value
    'sslverify' => false,
);

2. Check Server Availability: Ensure that your WordPress site is running properly on localhost and that the LMFWC REST API is accessible. Try accessing the REST API endpoint directly from your browser to see if it responds.

3. Check URL: Double-check the URL you are using in wp_remote_get and wp_remote_post. Make sure there are no typos or issues with the URL. Also, ensure that the consumer key and secret are correct.

4. Check for Firewall or Security Plugins: If you have any security or firewall plugins active on your WordPress site, they might be blocking external requests. Temporarily disable such plugins and see if the issue persists.

5. Server Resources: If you're working on localhost, ensure that your local server has enough resources available. Sometimes, resource limitations can lead to timeouts.

6. cURL Version: Ensure that cURL is installed and properly configured on your local server.

7. Check for Rate Limiting: Some APIs have rate limiting in place. Ensure that you are not making too many requests in a short time period.

8. Debugging: You can enable debugging in WordPress to get more detailed error information. Add the following to your wp-config.php file:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

This will log any PHP errors, warnings, or notices to a debug.log file in your WordPress wp-content directory. It might provide more information about the issue.

9. Use localhost IP: Instead of using get_site_url(), you can try using http://127.0.0.1 or http://localhost directly in your URL to see if it makes a difference.

10. Check for Server Load: If you're running other resource-intensive processes on your local server, they might affect the response time of your cURL requests.

If the issue persists after trying these steps, it may be worth reaching out to LMFWC support or checking their documentation for any specific configuration requirements or known issues related to cURL requests.

Your Answer

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

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