[wordpress插件] Async Background Worker异步后台工作者

wordpress 插件 文章 2020-02-22 10:40 562 0 全屏看文

AI助手支持GPT4.0

评分
0
描述

Async Background Worker, more information please visit this page https://

异步后台工作者,更多信息,请访问此页面 https://

tonjoo.github.io/async-background-worker/

tonjoo.github.io/async-background-worker/

Sample Usage

样品用量

What is it ?

是什么?

WordPress background worker plugin that enable WordPress to interact with beanstalkd work queue.

WordPress后台工作人员插件,使WordPress可以与beantalkd工作队列进行交互。

Why we need a worker ?

为什么我们需要一个工人?

We can run a very long task in the background, for example we need to import 100.000 row into WordPress databases.

我们可以在后台运行很长的任务,例如,我们需要将100.000行导入WordPress数据库。

Instead of doing the 100.000 import in one job, we can separate the job into many smaller job which is safer.

除了将10万个工作导入一个工作之外,我们还可以将工作分为许多更安全的较小工作。

WP-CLI

WP-CLI

Make sure you have WP CLI installed on your system

确保系统上已安装WP CLI

Support Forum

支持论坛

https://forum.tonjoostudio.com/

https://forum.tonjoostudio.com/

thread-category/async-background-worker/

thread-category / async-background-worker /

Add job to queue

将作业添加到队列

    1. Add new job to new worker queue using add_async_job command

      使用 add_async_job 命令将新作业添加到新的工作人员队列

      $job = new stdClass();

        $ job = new stdClass();

      // the function to run

      //要运行的函数

      $job->function = 'function_to_execute_on_background';

      $ job-> function ='function_to_execute_on_background';

      // our user entered data

      //我们的用户输入的数据

      $job->user_data = array('data'=>'some_data');

      $ job-> user_data = array('data'=>'some_data');

      add_async_job($job);

      add_async_job($ job);

    2. Implement function

      执行功能

      function function_to_execute_on_background($data) {    

        function function_to_execute_on_background($ data){    

      //do something usefull    

      //做一些有用的事情    

      echo "Background job executed successfully\n";

      回显“后台作业成功执行\ n”;

      }

      }

    3. Run wp background-worker listen

      运行 wp后台工作者监听

    Command

    命令

      • wp background-worker

        wp后台工作者

        Run Async Background Worker once.

        一次运行异步后台工作程序。

      • wp background-worker listen

        wp后台工作者监听

        Run Async Background Worker in loop (contiously), this is what you want for background worker.

        (连续)循环运行Async Background Worker(连续地),这就是您想要的Background Worker。

        WordPress framework is restart in each loop.

        WordPress框架会在每个循环中重新启动。

      • wp background-worker listen-daemon

        wp后台工作者监听守护程序

        Run Async Background Worker in loop (contiously) without restart the WordPress framework.

        循环(连续)运行Async Background Worker(连续地),而无需重新启动WordPress框架。

        NOTE if you use this mode, any code change will not be reflected.

        注意(如果使用此模式,则不会反映任何代码更改)。

        You must restart the Async Background Worker each time you change code.

        每次更改代码时,都必须重新启动“异步后台工作器”。

        This save memory and speed up thing.

        这样可以节省内存并加快速度。

下载地址
https://downloads.wordpress.org/plugin/async-background-worker.zip
-EOF-

AI助手支持GPT4.0