PHP Conference Japan 2024

GearmanJob::__construct

(PECL gearman >= 0.5.0)

GearmanJob::__construct建立 GearmanJob 實例

說明

public GearmanJob::__construct()

建立一個 GearmanJob 實例,表示 worker 要完成的工作。

參數

此函式沒有參數。

回傳值

一個 GearmanJob 物件。

新增筆記

使用者貢獻的筆記 1 則筆記

liv_romania at yahoo dot com
9 年前
通常您不需要建立 GearmanJob 物件。當使用 GearmanWorker::addFunction 時,GearmanJob 實例將會隨著工作伺服器被傳遞到已註冊的函式。

<?php
// 建立 worker
$worker= new GearmanWorker();

// 新增預設的工作伺服器 (localhost)
$worker->addServer('127.0.0.1', 4730);

// 定義一個變數來儲存應用程式資料
$count = 0;

// 新增反轉函式
$worker->addFunction('reverse', 'my_reverse_function', $count);

// 啟動 worker 監聽工作提交
while ($worker->work());

function
my_reverse_function(GearmanJob $job, &$count)
{
$count++;

return
$count . ': ' . strrev($job->workload()) . "\n";
}
?>
To Top