Behaviour of the unique ID argument:
If it's not provided, it defaults to a UUIDv1 (timestamp + mac address).
Otherwise, if a job with the same unique ID exists (i.e. is either queued or currently executing), then that job is used, not the one you're submitting. This does not apply to past (completed) jobs, and works across the entire job server pool, assuming no partitioning.
Or with code (the values in [brackets] are the server-assigned job identifiers):
<?php
$gearman->doBackground('sleep', '3', '123'); // [H:host:1] Starts sleep(3)
$gearman->doBackground('sleep', '5', '456'); // [H:host:2] Queues sleep(5)
$gearman->doBackground('sleep', '3', '123'); // [H:host:1] Does nothing
$gearman->doBackground('sleep', '1', '123'); // [H:host:1] Also does nothing (diff args don't trigger new jobs)
sleep (3);
// Job 123 [sleep(3)] has finished by now
$gearman->doBackground('sleep', '3', '123'); // [H:host:3] Starts a new job
?>GearmanClient::doBackground
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
GearmanClient::doBackground
Референца за `gearmanclient.dobackground.php` со подобрена типографија и навигација.
GearmanClient::doBackground
(PECL gearman >= 0.5.0)
GearmanClient::doBackground — (PECL gearman >= 0.5.0)
= NULL
$function, string $workload, ?string $unique = null): stringСтартирај задача во позадина
Параметри
function-
GearmanClient::do()
workload-
Регистрирана функција што работникот треба да ја изврши
unique-
Серијализирани податоци за обработка
Вратени вредности
Рачката за задачата за поднесената задача.
Примери
Стартува задача во позадина, враќајќи рачка за работа која може да се користи за добивање на статусот на задачата што се извршува.
Пример #1 Поднеси и следи задача во позадина
<?php
/* create our object */
$gmclient= new GearmanClient();
/* add the default server */
$gmclient->addServer();
/* run reverse client */
$job_handle = $gmclient->doBackground("reverse", "this is a test");
if ($gmclient->returnCode() != GEARMAN_SUCCESS)
{
echo "bad return code\n";
exit;
}
$done = false;
do
{
sleep(3);
$stat = $gmclient->jobStatus($job_handle);
if (!$stat[0]) // the job is known so it is not done
$done = true;
echo "Running: " . ($stat[1] ? "true" : "false") . ", numerator: " . $stat[2] . ", denominator: " . $stat[3] . "\n";
}
while(!$done);
echo "done!\n";
?>Горниот пример ќе прикаже нешто слично на:
Running: true, numerator: 3, denominator: 14 Running: true, numerator: 6, denominator: 14 Running: true, numerator: 9, denominator: 14 Running: true, numerator: 12, denominator: 14 Running: false, numerator: 0, denominator: 0 done!
Види Исто така
- Стартирај една задача и врати резултат [застарено] - Изврши една задача и врати резултат
- Излез на клиентот: GearmanClient::doHigh()
- - Изврши една задача со висок приоритет GearmanClient::doLow()
- - Изврши задача во позадина GearmanClient::doHighBackground()
- GearmanClient::doNormal() - Стартувај задача со низок приоритет во позадина