Zend_Feed_Pubsubhubbub.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 20043 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.feed.pubsubhubbub.introduction">
  5. <title>Zend_Feed_Pubsubhubbub</title>
  6. <para>
  7. <classname>Zend_Feed_Pubsubhubbub</classname> ist eine Implementation der PubSubHubbub Core
  8. 0.2 Spezifikation (Working Draft). Sie bietet eine Implementation eines Pubsubhubbub
  9. Publizisten und Abonnenten geeignet für den Zend Framework und andere PHP Anwendungen.
  10. </para>
  11. <sect2 id="zend.feed.pubsubhubbub.what.is.pubsubhubbub">
  12. <title>Was ist Pubsubhubbub?</title>
  13. <para>
  14. Pubsubhubbub ist ein offenes, einfaches Web-skalierbares Pubsub Protokoll. Der normale
  15. Anwendungsfall ist es Blogs (Publizist) zu erlauben Aktualisierungen von deren RSS oder
  16. Atom Feeds (Themen) an Abonnenten zu "senden". Diese Abonenten müssen dem RSS oder Atom
  17. Feed des Blogs über einen Hub abonniert haben. Das ist ein zentraler Server der
  18. benachrichtigt wird wenn es Aktualisierungen des Publizisten gibt und diese anschließend
  19. an alle Abonnenten verteilt. Jeder Feed kann bekanntgeben das er ein oder mehrere Hubs
  20. unterstützen indem ein Atom Namespaced Linkelement mit dem Rel Attribut "hub" verwendet
  21. wird.
  22. </para>
  23. <para>
  24. Pubsubhubbub hat Aufmerksamkeit erlangt weil es ein Pubsub Protokoll ist das einfach zu
  25. implementieren ist und über HTTP arbeitet. Seine Philosophie ist es das traditionelle
  26. Modell zu ersetzen indem Blog Feeds mit einem regulären Interfall abgefragt werden um
  27. Aktualisierungen zu erkennen und zu empfangen. Abhängig von der Frequenz der Abfrage
  28. kann es viel Zeit in Anspruch nehmen Aktualisierungen an interessierte Menschen bei
  29. Sammelstellen bis zu Desktop Lesern, bekannt zu machen. Mit der Verwendung eines
  30. Pubsub Systems werden Aktualisierungen nicht einfach von Abonnenten abgefragt sondern
  31. an die Abonnenten geschickt, was jegliche Verzögerung ausschaltet. Aus diesem Grund
  32. fungiert Pubsubhubbub als Teil von dem was als Echt-Zeit Web bekannt ist.
  33. </para>
  34. <para>
  35. The protocol does not exist in isolation. Pubsub systems have been around for a while,
  36. such as the familiar Jabber Publish-Subscribe protocol, XEP-0060, or the less well known
  37. rssCloud (described in 2001). However these have not achieved widespread adoption typically
  38. due to either their complexity, poor timing or lack of suitability for web applications.
  39. rssCloud, which was recently revived as a response to the appearance of Pubsubhubbub, has
  40. also seen its usage increase significantly though it lacks a formal specification and
  41. currently does not support Atom 1.0 feeds.
  42. </para>
  43. <para>
  44. Perhaps surprisingly given its relative early age, Pubsubhubbub is already in use including
  45. in Google Reader, Feedburner, and there are plugins available for Wordpress blogs.
  46. </para>
  47. </sect2>
  48. <sect2 id="zend.feed.pubsubhubbub.architecture">
  49. <title>Architecture</title>
  50. <para>
  51. <classname>Zend_Feed_Pubsubhubbub</classname> implements two sides of the Pubsubhubbub
  52. 0.2 Specification: a Publisher and a Subscriber. It does not currently implement a Hub
  53. Server though this is in progress for a future Zend Framework release.
  54. </para>
  55. <para>
  56. A Publisher is responsible for notifying all supported Hubs (many can be supported to
  57. add redundancy to the system) of any updates to its feeds, whether they be Atom or RSS
  58. based. This is achieved by pinging the supported Hub Servers with the URL of the updated
  59. feed. In Pubsubhubbub terminology, any updatable resource capable of being subscribed
  60. to is referred to as a Topic. Once a ping is received, the Hub will request the updated
  61. feed, process it for updated items, and forward all updates to all Subscribers
  62. subscribed to that feed.
  63. </para>
  64. <para>
  65. A Subscriber is any party or application which subscribes to one or more Hubs to receive
  66. updates from a Topic hosted by a Publisher. The Subscriber never directly communicates
  67. with the Publisher since the Hub acts as an intermediary, accepting subscriptions and
  68. sending updates to subscribed Subscribers. The Subscriber therefore communicates only
  69. with the Hub, either to subscribe/unsubscribe to Topics, or when it receives updates
  70. from the Hub. This communication design ("Fat Pings") effectively removes the possibility of
  71. a "Thundering Herd" issue. This occurs in a pubsub system where the Hub merely informs
  72. Subscribers that an update is available, prompting all Subscribers to immediately retrieve
  73. the feed from the Publisher giving rise to a traffic spike. In Pubsubhubbub, the Hub
  74. distributes the actual update in a "Fat Ping" so the Publisher is not subjected to any
  75. traffic spike.
  76. </para>
  77. <para>
  78. <classname>Zend_Feed_Pubsubhubbub</classname> implements Pubsubhubbub Publishers and
  79. Subscribers with the
  80. classes <classname>Zend_Feed_Pubsubhubbub_Publisher</classname> and
  81. <classname>Zend_Feed_Pubsubhubbub_Subscriber</classname>. In addition, the Subscriber
  82. implementation may handle any feed updates forwarded from a Hub by using
  83. <classname>Zend_Feed_Pubsubhubbub_Subscriber_Callback</classname>. These classes, their
  84. use cases, and APIs are covered in subsequent sections.
  85. </para>
  86. </sect2>
  87. <sect2 id="zend.feed.pubsubhubbub.zend.feed.pubsubhubbub.publisher">
  88. <title>Zend_Feed_Pubsubhubbub_Publisher</title>
  89. <para>
  90. In Pubsubhubbub, the Publisher is the party who publishes a live feed and frequently updates
  91. it with new content. This may be a blog, an aggregator, or even a web service with a public
  92. feed based API. In order for these updates to be pushed to Subscribers, the Publisher
  93. must notify all of its supported Hubs that an update has occured using a simple HTTP POST
  94. request containing the URI or the updated Topic (i.e the updated RSS or Atom feed). The Hub
  95. will confirm receipt of the notification, fetch the updated feed, and forward any updates to
  96. any Subscribers who have subscribed to that Hub for updates from the relevant feed.
  97. </para>
  98. <para>
  99. By design, this means the Publisher has very little to do except send these Hub pings
  100. whenever its feeds change. As a result, the Publisher implementation is extremely
  101. simple to use and requires very little work to setup and use when feeds are updated.
  102. </para>
  103. <para>
  104. <classname>Zend_Feed_Pubsubhubbub_Publisher</classname> implements a full Pubsubhubbub
  105. Publisher. Its setup for use is also simple, requiring mainly that it is configured with
  106. the URI endpoint for all Hubs to be notified of updates, and the URIs of all Topics to
  107. be included in the notifications.
  108. </para>
  109. <para>
  110. The following example shows a Publisher notifying a collection of Hubs about updates to
  111. a pair of local RSS and Atom feeds. The class retains a collection of errors which
  112. include the Hub URLs, so the notification can be re-attempted later and/or logged if any
  113. notifications happen to fail. Each resulting error array also includes a "response" key
  114. containing the related HTTP response object. In the event of any errors, it is strongly
  115. recommended to attempt the operation for failed Hub Endpoints at least once more at a
  116. future time. This may require the use of either a scheduled task for this purpose or
  117. a job queue though such extra steps are optional.
  118. </para>
  119. <programlisting language="php"><![CDATA[
  120. $publisher = new Zend_Feed_Pubsubhubbub_Publisher;
  121. $publisher->addHubUrls(array(
  122. 'http://pubsubhubbub.appspot.com/',
  123. 'http://hubbub.example.com',
  124. ));
  125. $publisher->addUpdatedTopicUrls(array(
  126. 'http://www.example.net/rss',
  127. 'http://www.example.net/atom',
  128. ));
  129. $publisher->notifyAll();
  130. if (!$publisher->isSuccess()) {
  131. // check for errors
  132. $errors = $publisher->getErrors();
  133. $failedHubs = array()
  134. foreach ($errors as $error) {
  135. $failedHubs[] = $error['hubUrl'];
  136. }
  137. }
  138. // reschedule notifications for the failed Hubs in $failedHubs
  139. ]]></programlisting>
  140. <para>
  141. If you prefer having more concrete control over the Publisher, the methods
  142. <methodname>addHubUrls()</methodname> and <methodname>addUpdatedTopicUrls()</methodname>
  143. pass each array value to the singular <methodname>addHubUrl()</methodname> and
  144. <methodname>addUpdatedTopicUrl()</methodname> public methods. There are also matching
  145. <methodname>removeUpdatedTopicUrl()</methodname> and
  146. <methodname>removeHubUrl()</methodname> methods.
  147. </para>
  148. <para>
  149. You can also skip setting Hub URIs, and notify each in turn using the
  150. <methodname>notifyHub()</methodname> method which accepts the URI of a Hub endpoint as
  151. its only argument.
  152. </para>
  153. <para>
  154. There are no other tasks to cover. The Publisher implementation is very simple since
  155. most of the feed processing and distribution is handled by the selected Hubs. It is
  156. however important to detect errors and reschedule notifications as soon as possible
  157. (with a reasonable maximum number of retries) to ensure notifications reach all
  158. Subscribers. In many cases as a final alternative, Hubs may frequently poll your
  159. feeds to offer some additional tolerance for failures both in terms of their own
  160. temporary downtime or Publisher errors/downtime.
  161. </para>
  162. </sect2>
  163. <sect2 id="zend.feed.pubsubhubbub.zend.feed.pubsubhubbub.subscriber">
  164. <title>Zend_Feed_Pubsubhubbub_Subscriber</title>
  165. <para>
  166. In Pubsubhubbub, the Subscriber is the party who wishes to receive updates to any Topic (RSS
  167. or Atom feed). They achieve this by subscribing to one or more of the Hubs advertised by
  168. that Topic, usually as a set of one or more Atom 1.0 links with a rel attribute of "hub". The
  169. Hub from that point forward will send an Atom or RSS feed containing all updates to that
  170. Subscriber's Callback URL when it receives an update notification from the Publisher. In
  171. this way, the Subscriber need never actually visit the original feed (though it's still
  172. recommended at some level to ensure updates are retrieved if ever a Hub goes offline). All
  173. subscription requests must contain the URI of the Topic being subscribed and a Callback URL
  174. which the Hub will use to confirm the subscription and to forward updates.
  175. </para>
  176. <para>
  177. The Subsciber therefore has two roles. To create and manage subscriptions, including
  178. subscribing for new Topics with a Hub, unsubscribing (if necessary), and periodically
  179. renewing subscriptions since they may have a limited validity as set by the Hub. This is handled
  180. by <classname>Zend_Feed_Pubsubhubbub_Subscriber</classname>.
  181. </para>
  182. <para>
  183. The second role is to accept updates sent by a Hub to the Subscriber's Callback URL, i.e.
  184. the URI the Subscriber has assigned to handle updates. The Callback URL also handles events
  185. where the Hub contacts the Subscriber to confirm all subscriptions and unsubscriptions.
  186. This is handled by using an instance of
  187. <classname>Zend_Feed_Pubsubhubbub_Subscriber_Callback</classname> when the Callback URL is
  188. accessed.
  189. </para>
  190. <important>
  191. <para>
  192. <classname>Zend_Feed_Pubsubhubbub_Subscriber</classname> implements the Pubsubhubbub 0.2
  193. Specification. As this is a new specification version not all Hubs currently implement
  194. it. The new specification allows the Callback URL to include a query string which is
  195. used by this class, but not supported by all Hubs. In the interests of maximising
  196. compatibility it is therefore recommended that the query string component of the
  197. Subscriber Callback URI be presented as a path element, i.e. recognised as a
  198. parameter in the route associated with the Callback URI and used by the application's
  199. Router.
  200. </para>
  201. </important>
  202. <sect3 id="zend.feed.pubsubhubbub.zend.feed.pubsubhubbub.subscriber.subscribing.and.unsubscribing">
  203. <title>Subscribing and Unsubscribing</title>
  204. <para>
  205. <classname>Zend_Feed_Pubsubhubbub_Subscriber</classname> implements a full Pubsubhubbub
  206. Subscriber capable of subscribing to, or unsubscribing from, any Topic via any Hub
  207. advertised by that Topic. It operates in conjunction with
  208. <classname>Zend_Feed_Pubsubhubbub_Subscriber_Callback</classname> which accepts requests
  209. from a Hub to confirm all subscription or unsubscription attempts (to prevent
  210. third-party misuse).
  211. </para>
  212. <para>
  213. Any subscription (or unsubscription) requires the relevant information before
  214. proceeding, i.e. the URI of the Topic (Atom or RSS feed) to be subscribed to for
  215. updates, and the URI of the endpoint for the Hub which will handle the subscription and
  216. forwarding of the updates. The lifetime of a subscription may be determined by the
  217. Hub but most Hubs should support automatic subscription refreshes by checking with
  218. the Subscriber. This is supported by <classname>Zend_Feed_Pubsubhubbub_Subscriber_Callback</classname>
  219. and requires no other work on your part. It is still strongly recommended that you use
  220. the Hub sourced subscription time to live (ttl) to schedule the creation of new subscriptions
  221. (the process is identical to that for any new subscription) to refresh it with the Hub.
  222. While it should not be necessary per se, it covers cases where a Hub may not support
  223. automatic subscription refreshing and rules out Hub errors for additional redundancy.
  224. </para>
  225. <para>
  226. With the relevant information to hand, a subscription can be attempted as
  227. demonstrated below:
  228. </para>
  229. <programlisting language="php"><![CDATA[
  230. $storage = new Zend_Feed_Pubsubhubbub_Model_Subscription;
  231. $subscriber = new Zend_Feed_Pubsubhubbub_Subscriber;
  232. $subscriber->setStorage($storage);
  233. $subscriber->addHubUrl('http://hubbub.example.com');
  234. $subscriber->setTopicUrl('http://www.example.net/rss.xml');
  235. $subscriber->setCallbackUrl('http://www.mydomain.com/hubbub/callback');
  236. $subscriber->subscribeAll();
  237. ]]></programlisting>
  238. <para>
  239. In order to store subscriptions and offer access to this data for general use,
  240. the component requires a database (a schema is provided later in this section).
  241. By default, it is assumed the table name is "subscription" and it utilises
  242. <classname>Zend_Db_Table_Abstract</classname> in the background meaning it
  243. will use the default adapter you have set for your application. You may also
  244. pass a specific custom <classname>Zend_Db_Table_Abstract</classname> instance
  245. into the associated model <classname>Zend_Feed_Pubsubhubbub_Model_Subscription</classname>.
  246. This custom adapter may be as simple in intent as changing the table name to use or as
  247. complex as you deem necessary.
  248. </para>
  249. <para>
  250. While this Model is offered as a default ready-to-roll solution, you may create your
  251. own Model using any other backend or database layer (e.g. Doctrine) so long as the
  252. resulting class implements the interface
  253. <classname>Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface</classname>.
  254. </para>
  255. <para>
  256. Behind the scenes, the Subscriber above will send a request to the Hub endpoint containing the
  257. following parameters (based on the previous example):
  258. </para>
  259. <table id="zend.feed.pubsubhubbub.zend.feed.pubsubhubbub.subscriber.subscribing.and.unsubscribing.table">
  260. <title>Subscription request parameters</title>
  261. <tgroup cols="3">
  262. <thead>
  263. <row>
  264. <entry>Parameter</entry>
  265. <entry>Value</entry>
  266. <entry>Explanation</entry>
  267. </row>
  268. </thead>
  269. <tbody>
  270. <row>
  271. <entry>hub.callback</entry>
  272. <entry>http://www.mydomain.com/hubbub/callback?xhub.subscription=5536df06b5dcb966edab3a4c4d56213c16a8184</entry>
  273. <entry>
  274. <para>
  275. The URI used by a Hub to contact the Subscriber and either request
  276. confirmation of a (un)subscription request or send updates from
  277. subscribed feeds. The appended query string contains a custom
  278. parameter (hence the xhub designation). It is a query string
  279. parameter preserved by the Hub and resent with all Subscriber
  280. requests. Its purpose is to allow the Subscriber to identify and
  281. look up the subscription associated with any Hub request in a
  282. backend storage medium. This is a non-standard parameter used by
  283. this component in preference to encoding a subscription key in the
  284. URI path which is more difficult to implement in a Zend Framework
  285. application.
  286. </para>
  287. <para>
  288. Nevertheless, since not all Hubs support query string parameters,
  289. we still strongly recommend adding the subscription key as a path component
  290. in the form http://www.mydomain.com/hubbub/callback/5536df06b5dcb966edab3a4c4d56213c16a8184.
  291. To accomplish this, it requires defining a route capable of parsing out the final
  292. value of the key and then retrieving the value and passing it to the Subscriber
  293. Callback object. The value would be passed into the method
  294. <methodname>Zend_Pubsubhubbub_Subscriber_Callback::setSubscriptionKey()</methodname>.
  295. A detailed example is offered later.
  296. </para>
  297. </entry>
  298. </row>
  299. <row>
  300. <entry>hub.lease_seconds</entry>
  301. <entry>2592000</entry>
  302. <entry>
  303. <para>
  304. The number of seconds for which the Subscriber would like a new
  305. subscription to remain valid for (i.e. a TTL). Hubs may enforce their own maximum
  306. subscription period. All subscriptions should be renewed by simply
  307. re-subscribing before the subscription period ends to ensure
  308. continuity of updates. Hubs should additionally attempt to automatically
  309. refresh subscriptions before they expire by contacting Subscribers (handled
  310. automatically by the Callback class).
  311. </para>
  312. </entry>
  313. </row>
  314. <row>
  315. <entry>hub.mode</entry>
  316. <entry>subscribe</entry>
  317. <entry>
  318. <para>
  319. Simple value indicating this is a subscription request.
  320. Unsubscription requests would use the "unsubscribe" value.
  321. </para>
  322. </entry>
  323. </row>
  324. <row>
  325. <entry>hub.topic</entry>
  326. <entry>http://www.example.net/rss.xml</entry>
  327. <entry>
  328. <para>
  329. The URI of the topic (i.e. Atom or RSS feed) which the Subscriber
  330. wishes to subscribe to for updates.
  331. </para>
  332. </entry>
  333. </row>
  334. <row>
  335. <entry>hub.verify</entry>
  336. <entry>sync</entry>
  337. <entry>
  338. <para>
  339. Indicates to the Hub the preferred mode of verifying subscriptions
  340. or unsubscriptions. It is repeated twice in order of preference. Technically
  341. this component does not distinguish between the two modes and treats both
  342. equally.
  343. </para>
  344. </entry>
  345. </row>
  346. <row>
  347. <entry>hub.verify</entry>
  348. <entry>async</entry>
  349. <entry>
  350. <para>
  351. Indicates to the Hub the preferred mode of verifying subscriptions
  352. or unsubscriptions. It is repeated twice in order of preference. Technically
  353. this component does not distinguish between the two modes and treats both
  354. equally.
  355. </para>
  356. </entry>
  357. </row>
  358. <row>
  359. <entry>hub.verify_token</entry>
  360. <entry>3065919804abcaa7212ae89.879827871253878386</entry>
  361. <entry>
  362. <para>
  363. A verification token returned to the Subscriber by the Hub when it
  364. is confirming a subscription or unsubscription. Offers a measure of
  365. reliance that the confirmation request originates from the correct
  366. Hub to prevent misuse.
  367. </para>
  368. </entry>
  369. </row>
  370. </tbody>
  371. </tgroup>
  372. </table>
  373. <para>
  374. You can modify several of these parameters to indicate a different preference. For
  375. example, you can set a different lease seconds value using
  376. <methodname>Zend_Pubsubhubbub_Subscriber::setLeaseSeconds()</methodname> or show a
  377. preference for the async verify mode by using <code>
  378. setPreferredVerificationMode(Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_ASYNC)</code>.
  379. However the Hubs retain the capability to enforce their own preferences and for this
  380. reason the component is deliberately designed to work across almost any set of options
  381. with minimum end-user configuration required. Conventions are great when they work!
  382. </para>
  383. <note>
  384. <para>
  385. While Hubs may require the use of a specific verification mode (both are supported
  386. by <classname>Zend_Pubsubhubbub</classname>), you may indicate a specific preference
  387. using the <methodname>setPreferredVerificationMode()</methodname> method. In "sync"
  388. (synchronous) mode, the Hub attempts to confirm a subscription as soon as it is
  389. received, and before responding to the subscription request. In "async"
  390. (asynchronous) mode, the Hub will return a response to the subscription request
  391. immediately, and its verification request may occur at a later time. Since
  392. <classname>Zend_Pubsubhubbub</classname> implements the Subscriber verification role
  393. as a separate callback class and requires the use of a backend storage medium, it
  394. actually supports both transparently though in terms of end-user performance,
  395. asynchronous verification is very much preferred to eliminate the impact of a
  396. poorly performing Hub tying up end-user server resources and connections for
  397. too long.
  398. </para>
  399. </note>
  400. <para>
  401. Unsubscribing from a Topic follows the exact same pattern as the previous example, with
  402. the exception that we should call <methodname>unsubscribeAll()</methodname> instead. The
  403. parameters included are identical to a subscription request with the exception that
  404. "hub.mode" is set to "unsubscribe".
  405. </para>
  406. <para>
  407. By default, a new instance of <classname>Zend_Pubsubhubbub_Subscriber</classname> will
  408. attempt to use a database backed storage medium which defaults to using the default
  409. <classname>Zend_Db</classname> adapter with a table name of "subscription".
  410. It is recommended to set a custom storage solution where these defaults are not apt either
  411. by passing in a new Model supporting the required interface or by passing a new instance
  412. of <classname>Zend_Db_Table_Abstract</classname> to the default Model's constructor to change
  413. the used table name.
  414. </para>
  415. </sect3>
  416. <sect3 id="zend.feed.pubsubhubbub.zend.feed.pubsubhubbub.subscriber.handling.hub.callbacks">
  417. <title>Handling Subscriber Callbacks</title>
  418. <para>
  419. Whenever a subscription or unsubscription request is made, the Hub must verify the
  420. request by forwarding a new verification request to the Callback URL set in the
  421. subscription/unsubscription parameters. To handle these Hub requests, which will include
  422. all future communications containing Topic (feed) updates, the Callback URL should trigger the
  423. execution of an instance of <classname>Zend_Pubsubhubbub_Subscriber_Callback</classname>
  424. to handle the request.
  425. </para>
  426. <para>
  427. The Callback class should be configured to use the same storage medium as the Subscriber
  428. class. Using it is quite simple since most of its work is performed internally.
  429. </para>
  430. <programlisting language="php"><![CDATA[
  431. $storage = new Zend_Feed_Pubsubhubbub_Model_Subscription;
  432. $callback = new Zend_Feed_Pubsubhubbub_Subscriber_Callback;
  433. $callback->setStorage($storage);
  434. $callback->handle();
  435. $callback->sendResponse();
  436. /**
  437. * Check if the callback resulting in the receipt of a feed update.
  438. * Otherwise it was either a (un)sub verification request or invalid request.
  439. * Typically we need do nothing other than add feed update handling - the rest
  440. * is handled internally by the class.
  441. */
  442. if ($callback->hasFeedUpdate()) {
  443. $feedString = $callback->getFeedUpdate();
  444. /**
  445. * Process the feed update asynchronously to avoid a Hub timeout.
  446. */
  447. }
  448. ]]></programlisting>
  449. <note>
  450. <para>
  451. It should be noted that
  452. <classname>Zend_Feed_Pubsubhubbub_Subscriber_Callback</classname> may independently
  453. parse any incoming query string and other parameters. This is necessary since PHP
  454. alters the structure and keys of a query string when it is parsed into the
  455. <varname>$_GET</varname> or <varname>$_POST</varname> superglobals. For example,
  456. all duplicate keys are ignored and periods are converted to underscores.
  457. Pubsubhubbub features both of these in the query strings it generates.
  458. </para>
  459. </note>
  460. <important>
  461. <para>
  462. It is essential that developers recognise that Hubs are only concerned with sending
  463. requests and receiving a response which verifies its receipt. If a feed update is
  464. received, it should never be processed on the spot since this leaves the Hub waiting
  465. for a response. Rather, any processing should be offloaded to another process or
  466. deferred until after a response has been returned to the Hub. One symptom of a
  467. failure to promptly complete Hub requests is that a Hub may continue to attempt
  468. delivery of the update/verification request leading to duplicated update attempts
  469. being processed by the Subscriber. This appears problematic - but in reality a
  470. Hub may apply a timeout of just a few seconds, and if no response is received within
  471. that time it may disconnect (assuming a delivery failure) and retry later. Note that
  472. Hubs are expected to distribute vast volumes of updates so their resources are
  473. stretched - please do process feeds asynchronously (e.g. in a separate process or
  474. a job queue or even a cron scheduled task) as much as possible.
  475. </para>
  476. </important>
  477. </sect3>
  478. <sect3 id="zend.feed.pubsubhubbub.zend.feed.pubsubhubbub.subscriber.setting.up.and.using.a.callback.url.route">
  479. <title>Setting Up And Using A Callback URL Route</title>
  480. <para>
  481. As noted earlier, the <classname>Zend_Feed_Pubsubhubbub_Subscriber_Callback</classname>
  482. class receives the combined key associated with any subscription from the Hub via one
  483. of two methods. The technically preferred method is to add this key to the Callback
  484. URL employed by the Hub in all future requests using a query string parameter with
  485. the key "xhub.subscription". However, for historical reasons, primarily that this was
  486. not supported in Pubsubhubbub 0.1 (it was recently added in 0.2 only), it is strongly
  487. recommended to use the most compatible means of adding this key to the Callback URL
  488. by appending it to the URL's path.
  489. </para>
  490. <para>Thus the URL http://www.example.com/callback?xhub.subscription=key would become
  491. http://www.example.com/callback/key.</para>
  492. <para>Since the query string method is the default in anticipation of a greater level
  493. of future support for the full 0.2 specification, this requires some additional work
  494. to implement.</para>
  495. <para>The first step to to make the <classname>Zend_Feed_Pubsubhubbub_Subscriber_Callback</classname>
  496. class aware of the path contained subscription key. It's manually injected therefore
  497. since it also requires manually defining a route for this purpose. This is achieved simply by
  498. called the method <methodname>Zend_Feed_Pubsubhubbub_Subscriber_Callback::setSubscriptionKey()</methodname>
  499. with the parameter being the key value available from the Router. The example below
  500. demonstrates this using a Zend Framework controller.</para>
  501. <programlisting language="php"><![CDATA[
  502. class CallbackController extends Zend_Controller_Action
  503. {
  504. public function indexAction()
  505. {
  506. $storage = new Zend_Feed_Pubsubhubbub_Model_Subscription;
  507. $callback = new Zend_Feed_Pubsubhubbub_Subscriber_Callback;
  508. $callback->setStorage($storage);
  509. /**
  510. * Inject subscription key parsing from URL path using
  511. * a parameter from Router.
  512. */
  513. $subscriptionKey = $this->_getParam('subkey');
  514. $callback->setSubscriptionKey($subscriptionKey);
  515. $callback->handle();
  516. $callback->sendResponse();
  517. /**
  518. * Check if the callback resulting in the receipt of a feed update.
  519. * Otherwise it was either a (un)sub verification request or invalid request.
  520. * Typically we need do nothing other than add feed update handling - the rest
  521. * is handled internally by the class.
  522. */
  523. if ($callback->hasFeedUpdate()) {
  524. $feedString = $callback->getFeedUpdate();
  525. /**
  526. * Process the feed update asynchronously to avoid a Hub timeout.
  527. */
  528. }
  529. }
  530. }
  531. ]]></programlisting>
  532. <para>Actually adding the route which would map the path-appended key
  533. to a parameter for retrieval from a controller can be accomplished using
  534. a Route configuration such as the INI formatted example below for use
  535. with <classname>Zend_Application</classname> bootstrapping.</para>
  536. <programlisting language="dosini"><![CDATA[
  537. ; Callback Route to enable appending a PuSH Subscription's lookup key
  538. resources.router.routes.callback.route = "callback/:subkey"
  539. resources.router.routes.callback.defaults.module = "default"
  540. resources.router.routes.callback.defaults.controller = "callback"
  541. resources.router.routes.callback.defaults.action = "index"
  542. ]]></programlisting>
  543. </sect3>
  544. </sect2>
  545. </sect1>