Problems with slow xml and json requests

Zan16

New Member
Im writing a website which shows some kind of livestreams from Own3d und Twitch. I had some Problems with the xml and json requests of the own3d and twitch api being slow so i contacted Own3d. They where really friendly, this is what they responded:\[quote\] Hello Jakob, Our API response time is normal, but the issue which you might be experiencing is because you are requesting information every time that your website is refreshed. What the majority of other sites do, such as clgaming.net is have a cron job run which gathers information roughly once every minute of which streams are online and offline, and writes to a local database so that it's fast when someone loads the website. Regards, The own3D.tv Support Team\[/quote\]So thats what i did, i wrote a PHP Script which writes the information into my Mysql Database, which i later will cronjob when i put the website online, it worked fine but with my database getting bigger I now experience problems again:I now have 65 streamers in my database and i have request time problems again i guess. First i got the error message "Fatal Error, max execution time of 30 seconds is exceeded. I thought no problem lets put the max execution time up. (ini_set('max_execution_time', 300);)What now happens is, that i get random errors of not working requests.for example:\[quote\] Warning: file_get_contents(http://api.justin.tv/api/stream/list.json?channel=schabs) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in D:\wamp\www\Lol Streamportal\database_actualize.php on line 20\[/quote\]It happens both for Own3d and twitch and as I said its random which streams will work and which one wont. Actually Im thinking that it should possible to get it working better, since clgaming f.ex has more than 1000 streams which probably have to be checked if online in their cronjob script.I thought before i contact own3d or twitch again i ask you guys, cause Im really not experienced at all with XML, neither with Json, maybe some of you have an Idea how to fix it, or maybe i should write the script not in PHP, but rather in JDBC or so??I dont want to show off my whole code, but i can give you the code of the functions which are causing the problems. (If really needed i can post the other code too)\[code\]function get_online($stream_id, $typ) { // Ownd3d Streams if($typ == 'o') { $xml = simplexml_load_file('http://api.own3d.tv/liveCheck.php?live_id='.$stream_id); $isLive = $xml->liveEvent->isLive; if($isLive == 'true') { return true; } else { return false; } } // Twitch Streams else if($typ == 't') { $api = "http://api.justin.tv/api/stream/list.json?channel=".$stream_id; $json = file_get_contents($api); $exist = strpos($json, $stream_id); if($exist) { return true; } else{ return false; } } else { return false; }}\[/code\]As i said, when my database was smaller i didn`t have problems at all. But since I got more than 50 entries I started to get problems.Thanks for alle answers.EDIT:I just got an idea. Perhaps twitch.tv and Own3d have a limited amount of requests allowed to sent in some time, maybe i will contact them about it. One thing i could to to solve this is to write 2 or 3 different scripts which only sents requests for the first 30 entries in the database, the second script for the next 30 and so on.
 
Back
Top