そのため、ユーザーがテキスト、画像、およびビデオの結果を取得できる検索のような機能をサイトに追加しています。
機能は至ってシンプル
<?php
// $query is passed from the search form input
function getVideo($query) {
$opts = array('https'=>array('header'=> 'Connection: close'));
$context = stream_context_create($opts);
$pattern = "/<title ?.*>(.*)<\/title>/";
preg_match($pattern, file_get_contents($query,false,$context), $matches);
return $matches[1];
}
スクレイピングする URL の例を次に示し ます https://gdata.youtube.com/feeds/api/videos?q=2013%20BMW%20X3%20xDrive28i&start-index=11&max-results=1
動画のタイトルを取得するだけで、6 秒かかります。助言がありますか?curl の使用に関する記事をいくつか読みましたが、多くの場合、サーバーの待機時間は短縮されません。