2017-02-07 8 views
0

gearman을 실행하면 단일 서버에서 3 명의 작업자가 제대로 작동하지만 4 번째 PHP 코드가 제대로 작동하지만 새로운 작업자를 감지 할 수 없으며 작업 대기열을 지우지 않습니다.동일한 서버에서 3 명 이상의 기어맨 작업자를 실행할 수 없습니다

protected function createWorker() 
{ 
    $this->worker = new \GearmanWorker(); 
    $config = $this->app->config->job_remote; 
    $this->worker->addServer($config['host'], $config['port']); 
    return $this->worker; 
} 
public function listen($eventType, $callback) 
{ 
    if (!($this->worker instanceof \GearmanWorker)){ 
     $this->worker = $this->createWorker(); 
    } 
    $this->worker->addFunction($eventType, $callback); 
    return $this->worker; 
} 

public function doWork($worker) 
{ 
    if (!($worker instanceof \GearmanWorker)){ 
     $worker = $this->createWorker(); 
    } 
    $this->worker = $worker; 
    while (1) { 
     $this->worker->work(); 
     $this->app->log->debug($this->worker->returnCode()); 
     if ($this->worker->returnCode() != \GEARMAN_SUCCESS) { 
      break; 
     } 
    } 
} 

우선이 방법 다음 'doWork'방법

클라이언트 측 코드 '들을'호출 오전 : GearmanManager 당신은 어떤 어떤 개까지 실행할 수 없습니다 사용

protected function createClient() 
    { 
     $this->client = new \GearmanClient(); 
     $config = $this->app->config->job_remote; 
     $this->client->addServer($config['host'], $config['port']); 
     return $this->client; 
    } 

    public function addTask($eventType, array $params) 
    { 
    if (!($this->client instanceof \GearmanClient)){ 
     $this->client = $this->createClient(); 
    } 
    // add single task in queue 
    $this->client->addTaskBackground($eventType, serialize($params)); 
    // Run task 
    $this->client->runTasks(); 
    } 
+0

당신의 코드는 어디에 있습니까 .. 무엇을 시도 했습니까 –

+0

코드를 추가했습니다. –

+0

클라이언트 코드는 어디에 있습니까 ??? 당신이 일자리를 할당 한 곳에서. –

답변

0

합니다. 의 근로자가 컴퓨터 속도를 늦추고 100 % CPU 및 100 % 메모리를 사용합니다.

Gearman.ini

[GearmanManager] 
worker_dir=./workers 
count=50 
dedicated_count=1 
max_worker_lifetime=3600 
auto_update=1 
log_file=./logs/WebAnalyzerWorker.log 
max_runs_per_worker=3 
timeout=600 

실행 Gearman을 노동자

./vendor/brianlmoon/gearmanmanager/pecl-manager.php -c ./gearman.ini -vvvvv 

노동자 클래스

<?php 

include dirname(__DIR__)."/vendor/autoload.php"; 

use Services\Log; 
use Services\ServiceInitialization; 
use Lib\Technology\FindWhoisRecords; 
use Illuminate\Database\Capsule\Manager as Capsule; 

class DomainDetailFetchJob{ 

    public function beforeRun() 
    { 
     ServiceInitialization::loadConfig(); 
     ServiceInitialization::loadDatabaseConfiguration(); 
    } 

    public function run($job, &$log) 
    { 
     $log[] = "Starting whois job"; 
     $collection = "whois"; 
     $this->beforeRun(); 
     ServiceInitialization::$config->all();   
     $workload = $job->workload(); 
     //workload 
     $whois = new FindWhoisRecords($workload); 
     if($whois->whois_result["err_code"]==0) { 
      $log[] = "Whois Info fetch successful"; 
      //success save the details 
      $whois->whois_result["result"]["workload"] = $workload; 
      Capsule::table($collection)->where("workload", $workload)->update($whois->whois_result["result"], ['upsert' => true]); 

     } 
     else { 
      $log[] = "Whois Info fetch failed"; 
      $logger = new Log(); 
      $logger->write($whois->whois_result["err_msg"], "error", "Whois Record Job"); 
      unset($logger); 
     } 
    } 

} 

Gearman을 클라이언트

$client = new GearmanClient(); 
$client->addServer(); 
$client->doBackground("DomainDetailFetchJob", $url);