Имеется ajax скрипт и php скрипт
$(document).ready(function(){
$(function(){
$(".users_find").on("click", function(){
$("#tbody").html("");
var from = $("#from").val().trim();
var to = $("#to").val().trim();
console.log($("#api").length);
var api = [];
api = $("#api").val().trim().split('\n');
console.log(api);
var xhr;
xhr = $.ajax({
method : "POST",
url: "search_by_id.php",
dataType:"json",
async: true,
data : {from : from, to : to, api : api},
beforeSend : function(){
$(".pred").show();
},
success:function(response){
for (var i = 1 ; i <= response.count; i++) {
$("#tbody").append("<tr>"+
"<td scope='row' id='ids'>"+response.id[i]+"</td>"+
"<td id='steam-ids'>"+
"<a class = 'ssid' href='https://steamcommunity.com/profiles/"+response.steamid[i]+"'>"+response.steamid[i]+"</a>"+
"</td>"+
"<td id='steam-names'>"+response.nickname[i]+"</td>"+
"<td id='steam-avatars'>"+"<img src="+response.avatar[i]+">"+"</td>"+
"<td id='steam-levels'><span id='steam_level' class='steam_level_"+lv(response.level[i])+"'><span id='level_num'>"+response.level[i]+"</span></span></td>"+
+"</tr>");
};
$(".pred").hide();
},
error : function(response){
console.log(response);
console.log('error!');
$(".pred").hide();
}
});
$("#fbt-cancel").on("click", function(){
xhr.abort();
});
});
});
});
<?php
set_time_limit(0);
ignore_user_abort(false);
function searcher($from, $to){
//Some settings
$_STEAMAPI = $_POST['api'][0];
$_STEAM_PTN = "76561197960265728";
$url_profile = "https://steamcommunity.com/profiles/";
$ptrn = "/^https:\/\/steamcommunity\.com\/profiles\/(7[0-9]{15,25}+)$/";
$count = 0;
$curl_objects = array();
//create table for json results
$json_array = array(
"id" => array(),
"steamid"=>array(),
"nickname"=>array(),
"avatar"=>array(),
"level"=>array(),
"mem"=>array(),
"count"=>$count
);
while ($from <= $to) {
$id32 = $from*2;
$id64 = bcadd($_STEAM_PTN , $id32);
$id64 = $url_profile.$id64;
if(preg_match($ptrn, $id64,$matches)){
$url_id64 = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches[1]";
$curl_objects[$from] = $url_id64;
};
$from++;
};
$multi_curl = curl_multi_init();
$channels = array();
foreach ($curl_objects as $curl_object) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curl_object);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($multi_curl, $ch);
$channels[$curl_object] = $ch;
}
$active = null;
do {
$mrc = curl_multi_exec($multi_curl, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($multi_curl) != -1) {
usleep(100);
}
do {
$mrc = curl_multi_exec($multi_curl, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
foreach ($channels as $channel) {
$result = curl_multi_getcontent($channel);
$result = json_decode($result);
foreach ($result->response->players as $player){
$steam['steamid']=$player->steamid;
$steam['name']=$player->personaname;
$steam['url']=$player->profileurl;
$steam['avatar']=$player->avatar;
$steam['mediumavatar']=$player->avatarmedium;
$steam['fullavatar']=$player->avatarfull;
$cvs = $player->communityvisibilitystate;
$ps = $player->profilestate;
if(($cvs == 1) || ($cvs == 2) || ($steam['steamid'] == null) || (empty($ps))){
continue;
} else {
$url = 'https://api.steampowered.com/IPlayerService/GetSteamLevel/v1/?key='.$_STEAMAPI.'&input_json={"steamid":'.$steam['steamid'].'}';
$jo = file_get_contents($url);
$jd = json_decode($jo);
$count++;
$json_array["id"][$count] = $count;
$json_array["steamid"][$count] = $steam['steamid'];
$json_array["nickname"][$count] = $steam['name'];
$json_array["avatar"][$count] = $steam['avatar'];
$json_array["level"][$count] = $jd->response->player_level;
$json_array["mem"][$count] = $cvs;
$json_array['count'] = $count;
$res = json_encode($json_array);
echo $res;
};
};
curl_multi_remove_handle($multi_curl, $channel);
};
curl_multi_close($multi_curl);
};
searcher($_POST['from'],$_POST['to']);
?>
Вопрос заключается в следующем: как выводить данные клиенту по мере выполнения php скрипта?
Виртуальный выделенный сервер (VDS) становится отличным выбором
Осуществляю прямую авторизация в вк,clientId и clientSecret получил из вк приложения,путем декомпилированияЗапрос вот такой json_decode(file_get_contents("https://oauth
При указании условия esle в цикле выводится не 1 значение переменной, а зацикленное значениеМассив вида: