0

所以我在我的网站上添加了一个类似搜索的功能,用户可以获得文本、图像和视频结果。

功能很简单

<?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];
}

这是一个抓取https://gdata.youtube.com/feeds/api/videos?q=2013%20BMW%20X3%20xDrive28i&start-index=11&max-results=1的示例网址

我需要做的就是获取视频的标题,这需要 6 秒。有什么建议么?我已经阅读了一些关于使用 curl 的文章,但对于许多人来说,它并没有减少服务器等待时间。

4

0 回答 0