Permalink
Browse files

Adds "beanstalk" client for putting errors on a beanstalk queue for s…

…ending later.
  • Loading branch information...
1 parent 2109781 commit cd14967178037e7cb85422efdce274d1d9b79d93 @aaronpk aaronpk committed Jun 30, 2011
Showing with 41 additions and 0 deletions.
  1. +22 −0 Services/Hoptoad.php
  2. +19 −0 beanstalk-daemon.php
View
22 Services/Hoptoad.php
@@ -437,6 +437,28 @@ public function curlRequest($url, $headers, $body)
}
/**
+ * Put the error on a beanstalk queue so a separate process can
+ * send it off to Hoptoad via HTTP. Requires the pheanstalk client.
+ * Config:
+ * $BEANSTALK_SERVERS[] = array(
+ * 'host' => 'example.com',
+ * 'port' => '11300'
+ * );
+ * @author Aaron Parecki
+ */
+ public function beanstalkRequest($url, $headers, $body)
+ {
+ global $BEANSTALK_SERVERS;
+ require_once('pheanstalk/pheanstalk_init.php');
+
+ $k = array_rand($BEANSTALK_SERVERS);
+ $pheanstalk = new Pheanstalk($BEANSTALK_SERVERS[$k]['host'], $BEANSTALK_SERVERS[$k]['port']);
+
+ $pheanstalk->useTube('hoptoad');
+ $pheanstalk->put(json_encode(array('url'=>$url, 'headers'=>$headers, 'body'=>$body)));
+ }
+
+ /**
* Send the request to Hoptoad using Zend
* @return integer
* @author Rich Cavanaugh
View
19 beanstalk-daemon.php
@@ -0,0 +1,19 @@
+<?php
+require_once('php-hoptoad-notifier/Services/Hoptoad.php');
+require_once('pheanstalk/pheanstalk_init.php');
+
+$hoptoad = new Services_Hoptoad(HOPTOAD_API_KEY);
+
+$k = array_rand($BEANSTALK_SERVERS);
+$pheanstalk = new Pheanstalk($BEANSTALK_SERVERS[$k]['host'], $BEANSTALK_SERVERS[$k]['port']);
+
+$pheanstalk->watch('hoptoad')->ignore('default');
+while($job = $pheanstalk->reserve())
+{
+ $data = json_decode($job->getData());
+
+ echo date('Y-m-d H:i:s') . ' Processing Error: ' . $data->url . "\n";
+ $hoptoad->curlRequest($data->url, $data->headers, $data->body);
+
+ $pheanstalk->delete($job);
+}

0 comments on commit cd14967

Please sign in to comment.