How achive serving multiple concurrent AjaxRest calls in plugin?

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 th

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745046500a4608130.html

相关推荐

  • How achive serving multiple concurrent AjaxRest calls in plugin?

    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 th

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信