[WordPress] 外掛分享: Async Background Worker

首頁外掛目錄 › Async Background Worker
10+
安裝啟用
尚無評分
3003 天前
最後更新
問題解決
WordPress 4.4+ v1.0 上架:2017-12-21

內容簡介

Async Background Worker 是一款 WordPress 外掛,詳細資訊請參閱此頁面 https://tonjoo.github.io/async-background-worker/

範例使用
這是什麼?

這是一款 WordPress 背景工作外掛,能夠讓 WordPress 與 beanstalkd 工作隊列互動。

為什麼需要工作隊列?

當我們需要在後台執行非常耗時的工作時,舉例來說,需要將 100,000 行資料匯入 WordPress 資料庫。我們可以將此任務分成多個較小的任務,這樣較為安全。

WP-CLI

確定您系統已安裝 WP CLI。

支援論壇

https://forum.tonjoostudio.com/thread-category/async-background-worker/

新增工作至隊列

使用 add_async_job 命令將新工作新增至新工作者隊列

$job = new stdClass();
// 要執行的函式
$job->function = 'function_to_execute_on_background';
// 使用者輸入的資料
$job->user_data = array('data'=>'some_data');
add_async_job($job);

實作函式

function function_to_execute_on_background($data) {
// 做一些有用的事
echo "背景工作已成功執行\n";
}

執行 wp background-worker listen

命令

wp background-worker
執行 Async Background Worker 一次。

wp background-worker listen
連續執行 Async Background Worker,這是後台工作者想要的。WordPress 框架在每個迴圈中都會重新啟動。

wp background-worker listen-daemon
連續執行 Async Background Worker 而不重新啟動 WordPress 框架。請注意,如果您使用這種模式,任何程式碼變更都不會反映出來。在更改程式碼時,必須每次重新啟動 Async Background Worker。這樣可以節省記憶體並加快速度。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Async Background Worker」→ 直接安裝(推薦)

原文外掛簡介

Async Background Worker, more information please visit this page https://tonjoo.github.io/async-background-worker/
Sample Usage
What is it ?
WordPress background worker plugin that enable WordPress to interact with beanstalkd work queue.
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. Instead of doing the 100.000 import in one job, we can separate the job into many smaller job which is safer.
WP-CLI
Make sure you have WP CLI installed on your system
Support Forum
https://forum.tonjoostudio.com/thread-category/async-background-worker/
Add job to queue

Add new job to new worker queue using add_async_job command
$job = new stdClass();
// the function to run
$job->function = 'function_to_execute_on_background';
// our user entered data
$job->user_data = array('data'=>'some_data');
add_async_job($job);

Implement function
function function_to_execute_on_background($data) {
//do something usefull
echo "Background job executed successfully\n";
}

Run wp background-worker listen

Command

wp background-worker
Run Async Background Worker once.

wp background-worker listen
Run Async Background Worker in loop (contiously), this is what you want for background worker. WordPress framework is restart in each loop.

wp background-worker listen-daemon
Run Async Background Worker in loop (contiously) without restart the WordPress framework. 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.

文章
Filter
Apply Filters
Mastodon