aboutsummaryrefslogtreecommitdiff
path: root/src/phinde/Queue.php
blob: 6c30faa7294c70c5af046aa4cbe2c61270445e44 (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
<?php
namespace phinde;

class Queue
{
    protected $gmclient;

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

    public function addToProcessList($linkUrl, $actions)
    {
        echo "Queuing for processing: $linkUrl"
            . ' (' . implode(',', $actions) . ')'
            . "\n";
        $this->gmclient->doBackground(
            $GLOBALS['phinde']['queuePrefix'] . 'phinde_process',
            serialize(
                array(
                    'url'     => $linkUrl,
                    'actions' => $actions,
                )
            )
        );
        if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
            echo 'Error queueing URL processing for '
                . $linkUrl . "\n"
                . 'Error code: ' . $this->gmclient->returnCode() . "\n";
            exit(2);
        }
    }
}
?>