views:

148

answers:

2

I'm trying to replace RSS polling with pubsubhubbub on my site. I'm able to use the subscriber library that google offers to send the subscription request. From the code it looks like it sends a post request via cURL with the RSS URL and a callback URL.

So this is where I need some direction:

In order to complete the subscription request my callback URL has to receive a GET request and then echo back a value from the GET request along with a 200 response. How do I get the parameters from the GET request? Is the echo done again via cURL? If so what option should include the 200 response?

+1  A: 

I am not sure whether I'm missing a point, but is this very simple script a start?

<?php

  echo $_GET["request_name"];

 ?>

this will output the GET parameter request_name and (implicitly) send a 200.

Pekka
That was the first thing I tried. The GET request is suppose to include a parameter called "hub.challenge". So I used $_GET and the tried writing the value to a txt file. I added a string as well, and it does reach the callback as it shows the string in the txt file but not the value from the parameter using $_GET.
$request = $_GET['hub.challenge'];fh = fopen('test.txt, 'a') or die("can't open file");fwrite($fh, 'Test: '.$request);fclose($fh);
Hmm. That looks o.k. and should definitely output a GET parameter of that name. The dot in the variable name shouldn't be a problem either. Can you confirm first that your script is acutally being called with the parameter, for example by checking the access logs? What is your PHP version?
Pekka
@transient-jet-lag: did you copy and paste that code? you're missing a `$` somewhere ... :)
munch
@transient-jet-lag - what do you see with print_r(); ?
Jay Zeng
@munch, typo, I typed it.
That looks all right. Can you follow @Jay Zeng's advice? You can write the result of the print_r operation into a file: `fwrite($fh, print_r($_GET, true));`
Pekka
Well now that's just sad, documentation and log specifies it as 'hub.challenge' and the print_r shows that it's hub_challenge.. Thanks everyone. Why is it almost always the most simple things?!?
Strange. Could that be PHP turning the `.` into a `_` to make it accessible as a variable (dots are forbidden in PHP variable names) It would be the first time that I hear this, though. On the other hand, the docs could lie but the logs won't.
Pekka
Yeah, I don't know what's going on with that either.. But at least now I can concentrate on echoing the request.. I think I know how, so I'll give you the credit.
Note: Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"]. From PHP doc.
Ooh, didn't know that! Very good to know. Thanks for the information.
Pekka
"<input name="a.b" /> becomes $_REQUEST["a_b"]" - weird, don't know this before. Thanks for sharing.
Jay Zeng
@transient-jet-lag - by the way, what version of PHP are you running?
Jay Zeng
Version is 5.2.6
A: 

There was recently a thread on the php-dev mailing list about this. The reason you can't access 'hub.challenge' in the $_GET superglobal is due to register_globals. Basically PHP cleans up any argument names before creating the superglobals. Any dots will be converted to underscores. It's looking to be 'fixed' in PHP 6, but not before due to BC issues.

Here's the thread about it.

James Logsdon