更新Ping(weblogUpdates.ping)をphpで送信する
HTTPのpostメソッドで、所定のフォーマットのXML(XML-RPC)を送信すればよい。
それを、関数の塊であるphpで、いかにさらっと書くか?
記述例
こんなのでどうでしょう。
file_get_contents()関数でPOSTリクエストを送信できるのは以前書いたとおり。
//更新Pingの送信先
$server = 'http://pingサーバーを指定/';
//更新Pingのリクエスト(形式はXML)を生成
//xmlrpc_encode_request()関数がない環境ではXMLを手作りすればよい
$content = xmlrpc_encode_request(
'weblogUpdates.ping',
array('ブログの名前', 'http://ブログのURL'),
array('encoding' => 'UTF-8')
);
//HTTPコンテキスト
//[http://www.php.net/manual/ja/context.http.php] 参照
$options = array('http'=>array(
'method' => 'POST',
'header' => 'Content-type: text/xml' . "\r\n"
. 'Content-length: ' . strlen($content),
'content' => $content
));
$context = stream_context_create($options);
//リクエスト送信
file_get_contents($server, false, $context);