aboutsummaryrefslogtreecommitdiff
path: root/src/phinde/Queue.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2016-02-10 14:56:20 +0100
committerChristian Weiske <cweiske@cweiske.de>2016-02-10 14:56:20 +0100
commitcd02bac646f42a0cb402ff2dc8240aa01f1f0fb8 (patch)
tree8cc7ee5d841f868e38ccc0b54d8cc6d33a852ed7 /src/phinde/Queue.php
parentf67e8f0bc3f51f2d280a86a8c7cffa68d812efe1 (diff)
downloadphinde-cd02bac646f42a0cb402ff2dc8240aa01f1f0fb8.tar.gz
phinde-cd02bac646f42a0cb402ff2dc8240aa01f1f0fb8.zip
rework crawler; add atom link extraction
Diffstat (limited to 'src/phinde/Queue.php')
-rw-r--r--src/phinde/Queue.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/phinde/Queue.php b/src/phinde/Queue.php
new file mode 100644
index 0000000..98f6462
--- /dev/null
+++ b/src/phinde/Queue.php
@@ -0,0 +1,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);
+ }
+ }
+}
+?>