add log class
[phinde.git] / src / phinde / Queue.php
1 <?php
2 namespace phinde;
3
4 class Queue
5 {
6     protected $gmclient;
7
8     public function __construct()
9     {
10         $this->gmclient = new \GearmanClient();
11         $this->gmclient->addServer('127.0.0.1');
12     }
13
14     public function addToProcessList($linkUrl, $actions)
15     {
16         Log::info(
17             "Queuing for processing: $linkUrl"
18             . ' (' . implode(',', $actions) . ')'
19         );
20
21         $this->gmclient->doBackground(
22             $GLOBALS['phinde']['queuePrefix'] . 'phinde_process',
23             serialize(
24                 array(
25                     'url'     => $linkUrl,
26                     'actions' => $actions,
27                 )
28             )
29         );
30         if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
31             Log::error(
32                 'Error queueing URL processing for '
33                 . $linkUrl . "\n"
34                 . 'Error code: ' . $this->gmclient->returnCode()
35             );
36             exit(2);
37         }
38     }
39 }
40 ?>