406f27e550e521bdbad25a5c20aaa15fa38ab1fb
[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 addToIndex($linkUrl, $linkTitle, $sourceUrl)
15     {
16         echo "Queuing for indexing: $linkUrl\n";
17         $this->gmclient->doBackground(
18             $GLOBALS['phinde']['queuePrefix'] . 'phinde_index',
19             serialize(
20                 array(
21                     'url'    => $linkUrl,
22                     'title'  => $linkTitle,
23                     'source' => $sourceUrl
24                 )
25             )
26         );
27         if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
28             echo 'Error queueing URL indexing for '
29                 . $linkUrl . "\n"
30                 . 'Error code: ' . $this->gmclient->returnCode() . "\n";
31             exit(2);
32         }
33     }
34
35     public function addToCrawl($linkUrl)
36     {
37         echo "Queuing for crawling: $linkUrl\n";
38         $this->gmclient->doBackground(
39             $GLOBALS['phinde']['queuePrefix'] . 'phinde_crawl',
40             serialize(
41                 array(
42                     'url' => $linkUrl
43                 )
44             )
45         );
46         if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
47             echo 'Error queueing URL crawling for '
48                 . $linkUrl . "\n"
49                 . 'Error code: ' . $this->gmclient->returnCode() . "\n";
50             exit(2);
51         }
52     }
53 }
54 ?>