aboutsummaryrefslogtreecommitdiff
path: root/src/phinde/Queue.php
blob: 98f6462cd90ccc7163c60605dbae106c2b17de18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace phinde;

class Queue
{
    protected $gmclient;

    public function __construct()
    {
        $this->gmclient = new \GearmanClient();
        $this->gmclient->addServer('127.0.0.1');
    }

    public function addToIndex($linkUrl, $linkTitle, $sourceUrl)
    {
        echo "Queuing for indexing: $linkUrl\n";
        $this->gmclient->doBackground(
            'phinde_index',
            serialize(
                array(
                    'url'    => $linkUrl,
                    'title'  => $linkTitle,
                    'source' => $sourceUrl
                )
            )
        );
        if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
            echo 'Error queueing URL indexing for '
                . $linkUrl . "\n"
                . 'Error code: ' . $this->gmclient->returnCode() . "\n";
            exit(2);
        }
    }

    public function addToCrawl($linkUrl)
    {
        echo "Queuing for crawling: $linkUrl\n";
        $this->gmclient->doBackground(
            'phinde_crawl',
            serialize(
                array(
                    'url' => $linkUrl
                )
            )
        );
        if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
            echo 'Error queueing URL crawling for '
                . $linkUrl . "\n"
                . 'Error code: ' . $this->gmclient->returnCode() . "\n";
            exit(2);
        }
    }
}
?>