简体   繁体   中英

Running gearman Worker PHP code in multiple machines

Im using multiple workers in my localhost Gearman server machine, where is all my code. Im thinking, if i run this worker elsewhere i must need to move all the the libraries im using to perform this task. Am i right?

Example: In this script im using FILE Class that also uses multiple libraries inside it.

namespace app\controllers;
use app\file\File;

require_once 'vendor/autoload.php';

$worker = new \GearmanWorker();
$worker->addServer();

$worker->addFunction('parse_file', function($job){
    echo "entrou no add function!<br>";
    print_r ($job->workload());
    sleep(2);
    new File($job->workload()); # this class parses the files content in database
});

while($worker->work())
{
  if ($worker->returnCode() != GEARMAN_SUCCESS)
  {
    echo "return_code: " . $worker->returnCode() . "\n";
    break;
  }
}

The answer is yes - you will need a copy of your libraries on each machine the workers will run on. You will need the FILE class and any dependencies.

You only need one copy of the codebase per machine, but you can run multiple instances of workers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM