admin管理员组

文章数量:1410697

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?

UPDATE 1

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 :

"my-url.de/wp-json/scs/v1/load/[any_int_here]"

(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.

本文标签: How achive serving multiple concurrent AjaxRest calls in plugin