I am developing a plugin that does at some point gather a bunch of data from a bunch of other servers.

So for each of these servers, there will be one ajax call in the frontend that expects xhr fields beeing returned as status updates on the progress like this:

Starting phase 1
Phase 1 done
Starting Phase 2

In the backend, the same function is loading the data via another rest but this is working fine. Simple Version here:

public function loader($args){
  $this->mysql($pdoinfo);      //excpects pdo connection information
  $this->connector($onninfo);  //then get all the data from the other database
  $this->migrateToDb($data);   //migrate the processed data into wordpress database

  //prints out progress via ob_flush() looks like above

The problem I found is that either with admin-ajax or WordPress rest API I can only serve 1 concurrent call at the same time.

Before I implemented these WordPress internal functions I had a simple connector.php in the plugin folder that did the same but outside the WordPress functionality. This one could do 6(I guess this is only my browser limit) at the same time. But it was outside of the Wordpress scope so I could not use the WordPress functions.

Is there any way with Wordpress API I can achieve the same performance? Or did I already fail when it comes to approaching this problem?


This is my REST API version so far.

 public function __construct()
        add_action('rest_api_init', array($this, 'register_rest_load'));

    public function register_rest_load()
        // Declare our namespace
        $namespace = 'scs/v1';

        // Register the route
        register_rest_route($namespace, '/load/(?P<id>\d+)', array(
            'methods'   => WP_REST_Server::ALLMETHODS,
            'callback'  => array($this, 'loader'),
            'args' => array()

When I make some ajax calls to :


(each call different int), all requests are pending until the one that is running is done. Checked via Chrome Developer Tools in the Network tab.

  • What's preventing you from handling multiple REST API requests at the same time? Are you referring to multiple REST requests over the same HTTP connection? Or are you talking about independent HTTP requests? How are you testing this and how does it fail? Or have I misunderstood? I notice there is no code in your question – Tom J Nowell Oct 29 '19 at 13:53
  • I added the REST version I have so far. I am making different HTTP-Requests I think. I mean I am sending multiple Ajax requests each scoping to the same URL with a different id at the end. It is NOT failing but the performance is too low. I want multiple concurrent requests being served at the same time. – Carlos Wedding Oct 29 '19 at 14:10
  • @TomJNowell ofc i forgot – Carlos Wedding Oct 29 '19 at 14:59
  • Without seeing your code that makes the requests it's difficult to advise, I suspect eitherway the problem isn't with WP but with the library that's making the requests not supporting Async/Parallel calls. I see no mechanism WP can use to prevent a second call being made via JS other than to have all concurrent requests waiting, but that would be difficult to implement in WP, and obvious in the network panel – Tom J Nowell Oct 29 '19 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.