9

I am wondering how to implement PubSubHubbub in a PHP site.I don't understand it.Can you explain me? I don't get the idea. The publisher notifies the subscriber and the subscriber - my site?

    <?php

// simple example for the PHP pubsubhubbub Subscriber
// as defined at http://code.google.com/p/pubsubhubbub/
// written by Josh Fraser | joshfraser.com | josh@eventvue.com
// Released under Apache License 2.0

include("PuSHSubscriber.php");

$hub_url = "http://pubsubhubbub.appspot.com";
$callback_url = "url to my site?";

$feed = "feed link";

// create a new subscriber
$s = new Subscriber($hub_url, $callback_url);

// subscribe to a feed
$s->subscribe($feed);
// unsubscribe from a feed
//$s->unsubscribe($feed);

?>

Or on $hub_url I should post my hub?

cweiske
  • 30,033
  • 14
  • 133
  • 194

2 Answers2

15

Looks like you're a subscriber, which means that you want to be notified upon updates in the feed. Here is the process :

  1. Find the hub url. There should be a <link> (or <atom:link>) element in the feed with rel="hub". The href contains the url of the hub. There are many different hubs out there!

  2. Implement a callback url. This url (which must be accessible from outside (so, not localhost!) will be called by the hub when new content is available for you. It should also implement the verification mechanism (see below)

  3. Perform the subscription request to the hub : it's a POST request to the hub url (see 1.) with the following params : hub.topic= hub.callback= hub.mode=subscribe hub.verify=sync (keep sync, as it's easier to debug).

  4. The hub will send a verification request to your callback, with a hub.verify_token param. Your app must then echo this param for the subscription to be validated.

  5. If all is fine, the hub will return 204 and you're good to go. If not, it will return a 4XX and you should check the body as it includes indications of what failed.

  6. Later, once the subscriptions is acknowledged, you will get POST requests with the content of the update in the body.

  7. (You have to re-subscribe every day. The actual time depends on what the hub tells you.)

Looks like you use an existing library. It should implement all the steps from above. Yet, it's something important to understand what's going on under the hood, so you may want to implement it yourself. It's not that complicated. Make sure that your callback is accessible from the "outside" and check that $s->subscribe($feed); doesn't actually return the outcome of the susbcription as it would help.

If you need a more complete PubSubHubbub tutorial, check this one.

Good luck!

cweiske
  • 30,033
  • 14
  • 133
  • 194
Julien Genestoux
  • 31,046
  • 20
  • 66
  • 93
  • Thanks, but can that url of the hub be my own hub , not that at pubsubhubbub.appspot.com –  Oct 03 '10 at 10:10
  • What info will give me the call to pubsubhubbub.appspot.com on new content ? –  Oct 03 '10 at 11:36
  • 1
    And no the hub url has to be the designated hub... because the hub cannot know if the feed was updated without the publisher telling it! – Julien Genestoux Oct 03 '10 at 15:19
  • I.e those at pubsubhubbub.appspot.com is OK,if the user put link with rel="hub" and href="pubsubhubbub.appspot.com" and notificate it on new content? –  Oct 03 '10 at 15:25
  • And one more.Will the hub return only the new content ,or it will return and a link to the updated feed? –  Oct 03 '10 at 15:29
  • 1
    It will push you the new content, as an Atom/RSS feed, so yes, it ill content any link. Maybe the best is to see by yourself :) – Julien Genestoux Oct 03 '10 at 19:01
0
  • $hub_url is the url of the 3rd party hub
  • $topic_url is the 'feed' you're subscribing to
  • $callback_url is the url on your server that should be pinged with new results as the hub gets them.

I hope that helps!

Jordan Warbelow-Feldstein
  • 10,510
  • 12
  • 48
  • 79
  • OK ,Blogger is pubsubhubbub-enabled.I give blogger's feed URL and I have this script ,but it doesn't work subscribe($feed); // unsubscribe from a feed //$s->unsubscribe($feed); ?> –  Oct 02 '10 at 19:15
  • 1
    subscriber_example.php must be a real file on your server, and may need to be a full url (http://...) – Jordan Warbelow-Feldstein Oct 02 '10 at 19:32
  • 1
    You're also unsubscribing right away anyway, it's not going to do much. – Jordan Warbelow-Feldstein Oct 02 '10 at 19:32
  • 1
    No, it won't work with localhost. If pubsubhubbub.appspot.com is your hub, think about what you're telling to do, from it's point of view... You're saying, when new data comes in, make sure to let localhost know that there's new data. Well, it says, OK I'm going to send this new data to localhost, but as far as it's concerned, localhost means to send the new data to itself, which means you'll never get it. You need to tell the remote server (the hub) how to send the data back to your actual servers. To do that, you need a full on url that will point the hub back to your server. – Jordan Warbelow-Feldstein Oct 03 '10 at 23:03