PHP卷曲分页:一种更快的方法?

PHP卷曲分页:一种更快的方法?,php,function,api,curl,instagram,Php,Function,Api,Curl,Instagram,我想通过Instagram API检索用户喜欢的所有媒体。Instagram目前返回了近300种喜欢的媒体,其端点如下: GET /users/self/media/liked 每个调用返回大约30个结果,因此我有大约10页要用curl函数扫描,这大约需要10秒 有没有更快的方法?我知道curl_multi允许你发射mu public function fetchLikes() { $url = 'https://api.instagram.com/v1/users/self/med

我想通过Instagram API检索用户喜欢的所有媒体。Instagram目前返回了近300种喜欢的媒体,其端点如下:

GET /users/self/media/liked
每个调用返回大约30个结果,因此我有大约10页要用curl函数扫描,这大约需要10秒

有没有更快的方法?我知道curl_multi允许你发射mu

public function fetchLikes() 
{
    $url = 'https://api.instagram.com/v1/users/self/media/liked?count=100&access_token=' . $access_token;

    while (isset($url) && $url != '') {  
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $jsonData = curl_exec($ch);
        curl_close($ch);

        $response = json_decode($jsonData);

        foreach ($response->data as $post) {

            echo $post->user->username . "<br>";
        }

        $url = $response->pagination->next_url;
    }
}
公共函数fetchLikes()
{
$url='1https://api.instagram.com/v1/users/self/media/liked?count=100&access_token=“.$access_令牌;
而(isset($url)&&$url!=''){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_头,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$jsonData=curl_exec($ch);
卷曲关闭($ch);
$response=json_decode($jsonData);
foreach($response->data as$post){
echo$post->user->username.“
”; } $url=$response->pagination->next_url; } }
在循环之前移动curl\u init()函数,在循环之后移动curl\u close(),即使这不是一项义务