WP Synchro Rest Error

I know this is an old topic, but we heard back from the WP Synchro dev with some amazing notes. I still need to do a little more work to reproduce and zero in on what exactly is going on, but in the spirit of being open and transparent, I thought I’d let the community know in case anyone else is interested in exploring a tough problem! :larry_heart:


But I found out the issue is actually way more weird than expected.

It is totally unrelated to WP Synchro also, but triggered by WP Synchro in the way it works.

I created a simple plugin file, which is attached in this email, that can be used to reproduce the issue on a fresh site.

Just drop the php file into /wp-content/plugins, activate it and go to frontpage. No other plugins are required.

Essentially the problem comes when doing more than one HTTP requests with WP internal functions, such as wp_remote_get() to the REST API of the same site.

Same site REST service is just for simplicity. We just call the base /wp-json.

The first request succeeds and all is great.

The second one times out with a curl error.

The third one succeeds.

The fourth one fails.

And so forth.

That’s the interesting part. Every other request fails with a CURL timeout and the other half succeed.

The timeout error, for every other request is:

cURL error 28: Operation timed out after 5003 milliseconds with 0 bytes received

This is not happening on WAMP for example, so it must be specific to the way LocalWP is working and I will assume you know a bit about that :blush:

I tried with different versions of PHP, all with same result also. Tried with and without SSL also.

Here’s the code for the basic WP plugin that causes this issue:

<?php
/*
  Plugin Name: LOCALWP TEST
  Plugin URI: https://succesprojekter.dk
  Description: Bla bla
  Version: 0.0.1
  Author: SuccesProjekter
  Author URI: https://succesprojekter.dk
  License: GPLv3
  License URI: http://www.gnu.org/licenses/gpl-3.0
 */

add_action('wp_head', function () {
  if (is_home()) {
    $result1 = wp_remote_get(get_rest_url());
    $result2 = wp_remote_get(get_rest_url());
    $result3 = wp_remote_get(get_rest_url());
    $result4 = wp_remote_get(get_rest_url());

    $results =  [$result1, $result2, $result3, $result4];

    $result_counter = 1;
    foreach ($results as $result) {
      if (is_wp_error($result)) {
	echo "<h1>Result {$result_counter} failed with error:</h1>";
	var_dump($result);
      } else {
	echo "<h1>Result {$result_counter} was good</h1>";
      }
      $result_counter++;
    }
  }
});