1<?php 2namespace DALMP\Queue; 3 4/** 5 * Gearman 6 * 7 * @author Nicolas de Bari Embriz <nbari@dalmp.com> 8 * @package DALMP 9 * @license BSD License 10 * @version 3.0.3 11 */ 12class Gearman implements QueueInterface 13{ 14 /** 15 * queue name 16 * 17 * @var string 18 */ 19 private $queue_name; 20 21 /** 22 * gearman host 23 * @var string 24 */ 25 private $host; 26 27 /** 28 * gearman port 29 * 30 * @var int 31 */ 32 private $port; 33 34 /** 35 * Constructor 36 * 37 * @param string $filename 38 * @param string $queue 39 * @param string $enc_key 40 */ 41 public function __construct($queue_name = 'dalmp_queue', $host = '127.0.0.1', $port = 4730) 42 { 43 $this->host = $host; 44 $this->port = $port; 45 $this->queue_name = $queue_name; 46 } 47 48 /** 49 * enqueue 50 * 51 * @param string $value 52 * @return boolean 53 */ 54 public function enqueue($value) 55 { 56 $gm = new \GearmanClient(); 57 $gm->addServer($this->host, $this->port); 58 $gm->queue_name = $this->queue_name; 59 60 if ($gm->ping('ping')) { 61 $job_handle = $gmclient->doBackground($this->queue_name, json_encode($value), md5($value)); 62 63 return ($this->gmclient->returnCode() != GEARMAN_SUCCESS) ? false : true; 64 } else { 65 return false; 66 } 67 } 68 69 /** 70 * dequeue 71 * 72 * @param string $key 73 */ 74 public function dequeue($limit = false) 75 { 76 $gm= new \GermanWorker(); 77 $gm->addServer($this->host, $this->port); 78 $gm->addFunction($this->queue_name, XXX); 79 } 80 81 /** 82 * delete element from queue 83 * 84 * @param string $value 85 */ 86 public function delete($key) 87 { 88 } 89 90 /** 91 * 92 * X execute/call custom methods 93 * 94 * @return queue object 95 */ 96 public function X() 97 { 98 return $this->gmclient; 99 } 100 101} 102