JSON for multiple streams (I have created a MONSTER, and not the good kind)

I created a website that shows all of the streamers on a particular ARK server. It functions, but it takes FOREVER to load, and I believe this is due to my poor coding choices. (http://arksurvivors.com/twitchrp)

At the moment I am pulling from the API, separately, for every single streamer:

$tashaxe_twitch = json_decode(curl_get_file_contents('https://api.twitch.tv/kraken/channels/tashaxe'), true);
$tashaxe_status = $tashaxe_twitch['status'];
$tashaxe_avatar = $tashaxe_twitch['logo'];
$tashaxe = json_decode(curl_get_file_contents('https://api.twitch.tv/kraken/streams/tashaxe'), true);
$tashaxe_viewers = $tashaxe['stream']['viewers'];
$tashaxe_online = false;
if ($tashaxe['stream'] !=NULL) {
$tashaxe_online = true;}

and outputting to

<li class="mix tashaxe zell selkie <?php if($tashaxe_online) { echo $tashaxe_status; } else { echo 'offline'; } ?> ">
<img src="<?php echo $tashaxe_avatar; ?>" alt="Image 1">
<p class="streamer"><a href="http://twitch.tv/tashaxe" target="_blank">Tashaxe</a</p>

It may be asking a lot, but is there any way to get the JSON to only have to run through once or twice? I feel like I’ve reeeeally taken the long way around on this one, and I apologize if this is a lot to ask. I just figured this would be a good place to start so that I may improve on such projects in the future.

You can solve your main problem by creating a Twitch account and following all the TwitchRP Streamers. Then use the Followers EndPoint instead.

That will narrow the number of requests down considerably, to Two (plus however many pages you need to iterate over)

Could you do something like a single query to

> https://api.twitch.tv/kraken/streams?channel=a51sarge,aderinn,apolloz,austenmarie,bbyruthless,commanderwtf,coolidgehd,darkdolphin,deadpoolyplays,dimitrisphotography,doggcrash,exotickitten,fistofthewalrus,gamewithme,geoppetto_hosseltoff,goatjacobs,greenysmiley,grimbug,joefudge91,kenmerritt,king4id,kiwion,kluna01,krytxx,letsmakefriends,lil_lexi667,littlebunnyfuufuu,lizzielue2,madmorph,magnussteen,mahswagger,mattdoza8,melton365,miss_cheevus,mizu21,montybrython,mrboombati,mrmoonshouse,mutha_t,mytala,naelphua,nerdstic,nuttyalmond,owlieandthenuttyalmond,pandapatrol22,pitbossgaming,pony_punch,rakshaal,reno_raines,reverberate,ridlich,rindeld,ruralpanda,sailoryas,selvek,shamrok7,silverfist91,sixmacs,sneakyshadower,tashaxe,tessann97,thebeardednoob,themacestation,thezombiepit,tvsboh,vaderrp,weefz,wishfuiiy,zeeramz,zizilla

For your “LIVE” page and leave “ALL” as a static page/list ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.