Gearman GearmanClient::doBackground

(PECL gearman >= 0.5.0)

GearmanClient::doBackground — 백그라운드에서 작업 실행


설명

public GearmanClient::doBackground(string $function_name, string $workload, string $unique = ?): string

백그라운드에서 작업을 실행하고 실행 중인 작업의 상태를 가져오는 데 사용할 수 있는 작업 핸들을 반환합니다.


매개변수

function_name
작업자가 실행할 등록된 함수
workload
처리할 직렬화된 데이터
unique
특정 작업을 식별하는 데 사용되는 고유 ID

반환 값

제출된 작업의 작업 핸들입니다.


Examples

예제 #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!
                

기타