略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: GearmanJob::__construct

2024-11-13

GearmanJob::__construct

(PECL gearman >= 0.5.0)

GearmanJob::__constructCreate a GearmanJob instance

说明

public GearmanJob::__construct()

Creates a GearmanJob instance representing a job the worker is to complete.

参数

此函数没有参数。

返回值

A GearmanJob object.

add a noteadd a note

User Contributed Notes 1 note

up
1
liv_romania at yahoo dot com
6 years ago
Usually you will not need to create a GearmanJob object. The GearmanJob instance will be passed to a registered function with the job server when GearmanWorker::addFunction is used:

<?php
// create the worker
$worker= new GearmanWorker();

// add the default job server (localhost)
$worker->addServer('127.0.0.1', 4730);

// define a variable to hold application data
$count = 0;

// add the reverse function
$worker->addFunction('reverse', 'my_reverse_function', $count);

// start the worker listening for job submissions
while ($worker->work());

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

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

官方地址:https://www.php.net/manual/en/gearmanjob.construct.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3