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
版权声明:本文标题:How achive serving multiple concurrent AjaxRest calls in plugin? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745046499a2639397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论