yiyunet 發表於 2013-11-22 09:24 % m/ h( b* d: t q& p( y
不會用pubhubsubbub。有實踐的來點介紹吧 - function http_post($url, $post_string) { ~7 }; {3 v( e2 g3 }
- $options = array(CURLOPT_URL => $url,$ p8 G, j( n- ?8 H0 p3 g r/ }
- CURLOPT_POST => true,
3 p! d- I0 v8 w. D. c& H9 n8 S - CURLOPT_POSTFIELDS => $post_string, P4 E9 N. x% H$ X: U
- CURLOPT_RETURNTRANSFER => true,
) e D( H( f4 O - CURLOPT_RETURNTRANSFER => true,, }9 o, a5 C- O! M; Z3 T, x0 y3 |9 W
- CURLOPT_USERAGENT => "PubSubHubbub-Publisher-PHP/1.0");
3 Q! I( @4 s1 Y/ S" | - $ch = curl_init();
/ J) l( P; F7 U/ q z - curl_setopt_array($ch, $options);' D3 P/ x: M5 g* L
- $response = curl_exec($ch);
( }! ?3 ~, y% h4 x! k - $info = curl_getinfo($ch);
`/ J3 U' [: n7 m4 `9 X' Y% x - curl_close($ch);
9 j8 Y( V8 b+ S' F: c - // all good
) a2 q. E1 {* T( B1 P% A5 | - if ($info['http_code'] == 204)0 b0 o1 H: S: P8 e' G# i0 W" a# i
- return true;4 v; Y4 Z) V5 m- @1 i$ f
- return false;* H5 o4 _0 B' Q% S# y$ W
- }
4 P/ j& M5 D# i/ m& v- r - function Publisher($topic_url){, W, M/ u9 ^$ a. _8 ^
- $hub_urls=array('http://pubsubhubbub.appspot.com/','http://pubsubhubbub.superfeedr.com/','http://superfeedr.com/hubbub');
+ S- p9 Q2 _ C; A: G8 P5 g8 a3 l) W - $post_string = "hub.mode=publish";
* m* z. R2 m+ Y& m4 V0 p$ I: [ o - $post_string .= "&hub.url=".urlencode($topic_url);
( I+ [# h* q+ x$ l- _, w, o - foreach ($hub_urls as $hub_url) {
( r6 U, }7 Q" l. d: v+ p - http_post($hub_url,$post_string);
) C3 X9 F8 g3 ` - }2 L" W0 i- l& b- l0 u
- }
複製代碼 以前從wp插件中扣的代碼,3個pub源) ?1 L2 g( e! O* |2 L& a" z5 o
, a1 y6 ~3 e) e% L5 \2 ?
; K' v5 d4 {. L; O$ ]( Z! b- `: ~ |