Created
April 20, 2013 22:10
-
-
Save angeorg/5427624 to your computer and use it in GitHub Desktop.
Gearman basic worker structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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