yiyunet 發表於 2013-11-22 09:24 ( j' l; \$ I$ u0 j+ f' S& M
不會用pubhubsubbub。有實踐的來點介紹吧 - function http_post($url, $post_string) {
: p9 R* \; W1 m0 h5 h - $options = array(CURLOPT_URL => $url,
* H7 H+ Y4 H$ r. P2 A' n0 s - CURLOPT_POST => true,, Y, j9 g0 w: N" ?1 a% A+ t3 h3 {/ w
- CURLOPT_POSTFIELDS => $post_string,6 ?# J( S# N5 e. H7 E% Q9 n
- CURLOPT_RETURNTRANSFER => true,
0 c, {- ?; b/ X. k; B' W - CURLOPT_RETURNTRANSFER => true,; z6 ~: U3 O# w1 g/ I4 c' u
- CURLOPT_USERAGENT => "PubSubHubbub-Publisher-PHP/1.0");
4 Y0 p8 a* Q# L, F' `0 P3 i3 p: l - $ch = curl_init();5 ?6 D2 ?$ Q" i2 x
- curl_setopt_array($ch, $options);
9 Y7 [% G9 I8 Y5 H8 n2 a* ~4 j - $response = curl_exec($ch);
4 H- w. e) ^5 c% ? - $info = curl_getinfo($ch);
1 E+ @ J) y6 p" m4 u - curl_close($ch);2 ~; Y( a6 A$ I/ m
- // all good4 N! y0 Z+ ]9 m' Z
- if ($info['http_code'] == 204)) \8 n! s0 D: K3 l8 j" a, Y
- return true;
, e8 Z% N8 a$ T3 L8 Z* _ - return false;) F8 I! W. u, ] X
- }
9 X Y' P7 \9 `3 B8 I2 a$ T, Y - function Publisher($topic_url){
* D4 }( o, q4 h - $hub_urls=array('http://pubsubhubbub.appspot.com/','http://pubsubhubbub.superfeedr.com/','http://superfeedr.com/hubbub');
1 i3 X# `8 r# Y7 ~2 d - $post_string = "hub.mode=publish";- P9 S9 V3 S$ e* \, s, C
- $post_string .= "&hub.url=".urlencode($topic_url);
6 X+ }* f: ]( | - foreach ($hub_urls as $hub_url) {
! ^, R6 Y3 U' `* Z: j: ] - http_post($hub_url,$post_string);; ~6 E; d+ u% A. x7 e
- }* i" C3 ]" Q+ m0 M0 a
- }
複製代碼 以前從wp插件中扣的代碼,3個pub源
6 g5 p: B. N, ?! z a& _
5 Y5 q6 ~% C/ ^* V7 c! A7 n! s1 \$ D- c' t% P4 Z" H0 I
|