Skip to content

Instantly share code, notes, and snippets.

@angeorg
Created April 20, 2013 22:10
Show Gist options
  • Select an option

  • Save angeorg/5427624 to your computer and use it in GitHub Desktop.

Select an option

Save angeorg/5427624 to your computer and use it in GitHub Desktop.
Gearman basic worker structure
<?php
class Worker
{
public function __construct($host, $port)
{
$this->worker = new GearmanWorker();
$this->worker->addServer($host, $port);
echo 'Waiting for work...' . PHP_EOL;
}
public function set_id_prefix($worker_id_prefix)
{
$this->worker->setId($worker_id_prefix . uniqid(true));
}
public function register_function($function)
{
$this->worker->addFunction($function, array($this, $function . '_action'));
}
public function run()
{
while($this->worker->work())
{
if ($this->worker->returnCode() != GEARMAN_SUCCESS)
{
echo $this->worker->returnCode() . PHP_EOL;
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment