WP Synchro Rest Error

Hello,

I am trying to use wpsynchro:

with local wp however I get the following error message:

REST error - Cannot reach ‘initiate’ REST service - Check that REST services is accessible and not being blocked

Please see screenshot below:

I’m not sure if this error is because WP Synchro is not compatible with local wp or if I need to upgrade to pro to get it working.

Either case if someone could please let me know if would be greatly appreciated.

Regards,

Matt

Hey @mattfraser, welcome to the forums!

I was able to take a closer look at this plugin and I think that everything should be working it looks like everything is supposed to working correctly. To be specific, I zeroed in on the REST endpoint that the plugin is trying to reach and was able to reach it via curl:

The one thing that seems odd (or maybe be contributing) is that there’s a bunch of binary data (I think from gzip) in the response, which I think would be related to the DEFLATE header.

Are you able to reach out to the WPSynchro devs to get a better idea of what their test is trying to do and the kind of configuration that they are needing for the plugin to work?

Hey Ben,

Thanks for looking into this for me. I did reach out to the developer and heard back from him:

Yes, this is a known issue with LocalWP.

The short story is that LocalWP runs in a virtual machine, where the site cannot call services on itself.

And because WP Synchro does that, it fails.

A few guys from LocalWP just contacted me (based on your question on Twitter) and I sent them a long explanation about the issue and how they can fix it.

I just sent it 5 mins ago, so hopefully they will fix it on their end as it might also generate problems with other plugins.

There is no current workaround to get it working, until they either make a fix or I change WP Synchro to work in another way.

If I hear something from them, I will let you know.

I highly enjoyed using Local WP for the most part but I have discovered another local server solution and have made the switch and WP Synchro is working with it.

Had Local WP had a solution, such as Magic Sync as a standalone plugin rather than only working with wpengine or getflywheel hosting I would have gladly paid for it.

If Local WP does find a way to get plugins like WP Synchro working with it, I would be glad to consider moving back.

Regards,

Matt

Thanks for getting back to this post! I’m glad that the devs are talking, especially since this piece of information is no longer accurate with the latest version of Local (+5.x).

We’re always looking for ways to improve Local, but I’m also glad you found a solution that works for your needs!

Hey Matt,

Appreciate the follow-up. As WP Synchro said, we e-mailed them and we’re in communication.

It’s worth pointing out that this is not entirely accurate. While Local did use virtualization in Local Classic, we accounted for this specific use-case of sites needing to ping themselves or other Local sites.

Like @ben.turner, in newer versions of Local (v5+), Local relies on native services that have access to the host’s networking layer which means whatever you can access in your browser, the Local site should be able to as well.


I hope that all makes sense and helps the WP Synchro devs zero in on what’s going on! As much as you and WP Synchro, we’re eager to get to the bottom of this!

Clay, thanks so much for responding. I switched to using laragon as I discovered it on the WP Synchro website and got it seamlessly working without any effort.

However…I do prefer Local WP and am glad you created it.

I’ll try to reinstall Local WP and see if I can get it working and if not, I’ll submit some logs.

Regards,

Matt

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

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++;
    }
  }
});

I refactored the above PHP and tested 50 requests, but wasn’t able to reproduce:

<?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
 */

function my_make_request()
{
	return wp_remote_get(get_rest_url());
}

function my_test_rest($times = 10)
{
    ob_start(); ?>
    <ul id="failing-rest">
	<?php for ($i = 1; $i < $times; ++$i) {
	    $result = my_make_request();
	    if (is_wp_error($result)) {
		echo sprintf('<li><p>Result %s failed with Error:\n%s', $i, var_dump($result));
	    } else {
		echo sprintf('<li><p>Result %s was successful.', $i);
	    }
	} ?>
    </ul>
    <?php
    return ob_get_clean();
}

add_action('wp_footer', function () {
    if (is_home()) {
	echo my_test_rest(50);
    } 
});

Hi Ben,

Thanks for testing it out. I did some further testing to determine what might be going on.
Since you could not reproduce it, I had the idea that it might be OS related.

So i did some testing and it turns out that on 3 of out 3 computers with LocalWP running on Windows 10 had this problem. One of them is clean Windows 10 VM, offered by Microsoft, found here:
https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/
So that should be faily easy to reproduce using that image.

I also tried using a clean new Ubuntu 20.04, on which everything worked as it should.
I could not try it on Mac, since i do not own one. But Mac is pretty much Linux-like :slight_smile:

So it would seem to be a issue only on Windows.
I have only tested on Win10 machines, so i do not know about other Windows versions.
I tested with latest LocalWP version, v. 6.1.2

I tested with both my first test script and yours.
Same result, one half succed and other half fails, alternating, like this:

  • Result 1 was successful.

C:\Users\User\Local Sites\wpsynchro\app\public\wp-content\plugins\wpsynchro-rest-test.php:25: object(WP_Error)[879] public ‘errors’ => array (size=1) ‘http_request_failed’ => array (size=1) 0 => string ‘cURL error 28: Operation timed out after 5000 milliseconds with 0 bytes received’ (length=80) public ‘error_data’ => array (size=0) empty protected ‘additional_data’ => array (size=0) empty

  • Result 2 failed with Error:\n
  • Result 3 was successful.

C:\Users\User\Local Sites\wpsynchro\app\public\wp-content\plugins\wpsynchro-rest-test.php:25: object(WP_Error)[882] public ‘errors’ => array (size=1) ‘http_request_failed’ => array (size=1) 0 => string ‘cURL error 28: Operation timed out after 5011 milliseconds with 0 bytes received’ (length=80) public ‘error_data’ => array (size=0) empty protected ‘additional_data’ => array (size=0) empty

  • Result 4 failed with Error:\n
  • Result 5 was successful.

C:\Users\User\Local Sites\wpsynchro\app\public\wp-content\plugins\wpsynchro-rest-test.php:25: object(WP_Error)[885] public ‘errors’ => array (size=1) ‘http_request_failed’ => array (size=1) 0 => string ‘cURL error 28: Operation timed out after 5011 milliseconds with 0 bytes received’ (length=80) public ‘error_data’ => array (size=0) empty protected ‘additional_data’ => array (size=0) empty

  • Result 6 failed with Error:\n

C:\Users\User\Local Sites\wpsynchro\app\public\wp-content\plugins\wpsynchro-rest-test.php:25: object(WP_Error)[872] public ‘errors’ => array (size=1) ‘http_request_failed’ => array (size=1) 0 => string ‘cURL error 28: Operation timed out after 5000 milliseconds with 0 bytes received’ (length=80) public ‘error_data’ => array (size=0) empty protected ‘additional_data’ => array (size=0) empty

  • Result 7 failed with Error:\n
  • Result 8 was successful.

C:\Users\User\Local Sites\wpsynchro\app\public\wp-content\plugins\wpsynchro-rest-test.php:25: object(WP_Error)[891] public ‘errors’ => array (size=1) ‘http_request_failed’ => array (size=1) 0 => string ‘cURL error 28: Operation timed out after 5013 milliseconds with 0 bytes received’ (length=80) public ‘error_data’ => array (size=0) empty protected ‘additional_data’ => array (size=0) empty

  • Result 9 failed with Error:\n
  • Result 10 was successful.

C:\Users\User\Local Sites\wpsynchro\app\public\wp-content\plugins\wpsynchro-rest-test.php:25: object(WP_Error)[894] public ‘errors’ => array (size=1) ‘http_request_failed’ => array (size=1) 0 => string ‘cURL error 28: Operation timed out after 5006 milliseconds with 0 bytes received’ (length=80) public ‘error_data’ => array (size=0) empty protected ‘additional_data’ => array (size=0) empty

  • Result 11 failed with Error:\n

** Removed rest of result, as it proves the point.

Hope you have time to take a look at it.

Thanks!

Brian Søgård Jensen / WP Synchro

1 Like

Nice! Thanks for helping me zero in on it!

I was testing under MacOS. I should be able to fire up my Windows machine next week to get a better idea of what’s going on!

Well, I’m on a mac and I have always had the rest error (on the plugin admin screen). Please forgive me, if I’ve missed some nuance here in your debugging process/conversation.

Nice! I’ve never been able to replicate on my mac, so maybe you can help me zero in on reliable replication steps?

Can you try this:

  1. Create a new site, and install the WP Synchro plugin. Make a note of the domain for that site.

  2. After the site is set up, open a terminal

  3. Run this command using the domain from your test site:

    curl -X POST http://example.local
    
  4. Share the output of that command here in the forums. Can you also take a screenshot of what you are seeing within Local, the browser, and the terminal?

Hey Ben. Sorry For the late replay. The terminal command you sent me just returned a dump of the html of index.php

Ah, thanks for that screenshot.

To be clear, I do see the error within the WP Admin, however, (I think) I’m able to navigate to and make a request to the REST endpoint that this health check screen is trying to access:

As a test, I also tried using WordPress’ wp_remote_post() function within a theme and that is able to hit that REST endpoint:

At this point it feels mostly like a bug with the health-check functionality of the plugin since I’m able to reach the endpoint that it mentions both from a regular REST client as well as the wp_remote_post() function.

Just wanted to say i’m waiting for a solution also :slight_smile:

In your:
/etc/apache2/sites-available/000-default.conf

File add something like this:

<Directory “/var/www/wordpress”>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Require all granted

Alias /blog /var/www/wordpress

restart apache and will not get this error.

-Raymond Day

I’m not sure that’s the actual solution @Raymond.

This topic in the forums seems to be focused on Nginx under the tool Local

The instructions that you gave seem to be meant for running an apache process under a Linux environment.

Can you give a little more detail about how you fixed this topic’s issue?