Good day, gentlemen. Your help in an easy task is necessary, alas, for me because of a lack of experience it turned out to be difficult.
I work with VK API. I search for groups by name via groups.search (for example, music / games / movies), I get a list of foreach ($data1['response'] as $item) and display the name and picture of the group.
Then I need to get the number of members for each group, this can be done through the groups.getMembers method groups.getMembers typing group_id , but I can get group_id only during foreach ($data1['response'] as $item) . If I do this, then in principle everything works, but the speed drops significantly, and the page starts loading in 3-5 seconds. It even seems to me that the script does not have time to work out to the end, because for some groups I don’t get the number of participants.
Maybe I am doing something wrong, but it seems to me that this is so, and it can be implemented differently, but I don’t know how. I would be grateful for any help or hint in which direction to dig.
Here is my code:
<?php //Получаю список групп $url1 = file_get_contents("https://api.vk.com/method/groups.search?q=".$_POST['vkgroup']."&access_token=*MYTOKEN*"); //ССылка на получение количество пользователей $url2 = "https://api.vk.com/method/groups.getMembers?group_id="; $data1 = json_decode($url1,true); foreach ($data1['response'] as $item) { //Получаю список участников в группе $url3 = file_get_contents($url2.$item['screen_name']); $data2 = json_decode($url3,true); //Получаю цифрой количество участников $cuser=$data2['response']['count']; //Вывожу количество участников echo $cuser; //Вывожу картинку группы echo "<img src=".$item['photo']."> "; //Вывожу название группы echo $item['name']."<br>"; } ?>