1. I have corrected the e-mail settings so that outgoing e-mails from these forums should be sent now. If you tried to Register or Reset your Password, please try again!
    Dismiss Notice

[PLANETSIDE 2] error :(

Discussion in 'Census: Planetside 2' started by shinigai, Mar 15, 2013.

  1. shinigai

    shinigai Guest

    Hey all I am having problems this code works for most quieries but when a large set gets called it errors out with this

    Code:
    <span style="font-size: xx-small;">Warning: Invalid argument supplied for foreach() in functions-outfit.php on line [i]248[/i]
    the first few values pass successfully then it errors out then dispalys more and once again errors <img src="/smilies/1cfd6e2a9a2c0cf8e74b49b35e2e46c7.gif" border="0" alt="SMILEY" /> here is the code

    here is the code I use <img src="/smilies/9d71f0541cff0a302a0309c5079e8dee.gif" border="0" alt="SMILEY" />

            $ApiLink     = "http://census.daybreakgames.com/s:egrazziani/get/ps2-beta/outfit/" . $outfit_id . "?c:resolve=member_online_status&c:resolve=member_character(stats.damage_given.value,stats.vehicle_kills.value,stats.score.value,stats.facility_capture_count.value,stats.hit_count.value,stats.damage_taken.value,stats.kill_death_ratio.value,stats.revenge_count.value,stats.assist_count.value,stats.play_time.value,stats.headshots.value,stats.fire_count.values,stats.deaths.value,stats.facility_defended_count.value,stats.kills.value,stats.type,member_since,name.first,experience,character_id,online_status)";        $json_decode = (json_decode(file_get_contents($ApiLink), true));        $output      = $json_decode["outfit_list"];        $total_score = "0";        foreach ($output as $key => $value) {            $members[$key] = $output[$key]["members"];            foreach ($members[$key] as $row) {                $total_socre = $row['experience'];                var_dump($total_score);                foreach ($total_socre as $expier) {                    $score = $expier['score'];                    $total_score += $score;                }            }            echo number_format($total_score);        }

    thanks for any help!

     
  2. feldon30

    feldon30 Guest

    Which of the foreach statements is line 248?

     
  3. Dedith

    Dedith Guest

  4. shinigai

    shinigai Guest

    whoops the error is the  area here

    foreach ($total_socre as $expier) {                    $score = $expier['score'];                    $total_score += $score;                }

     
  5. Dethdlr

    Dethdlr Guest

    We most certainly did.  :)



    I was going to point that out, but looks like you found it.  

    Dedith is right though.  If you're expecting the data to always have the fields you want, then you should also be expecting to see random errors generated from your code.

     
  6. shinigai

    shinigai Guest

    yeah thanks <img src="/station/images/smilies/3b63d1616c5dfcf29f8a7a031aaa7cad.gif" border="0" /> first time using API's I appreciate the super fast response <img src="/smilies/283a16da79f3aa23fe1025c96295f04f.gif" border="0" alt="SMILEY" /> another Q :)

    do you guys know a better way to call the api using functions to make my code more efficient?

    here is what I got going on now a small example of 2 functions that call different items the result is this

    Code:
    135,604,190396,704,722This page took 6.276720 seconds to load.If I run the script again the time goes from 6 seconds toThis page took 0.480891 seconds to load.super random I guess its the API being slow? would it be wise to consider caching? to help prevent the api messing up the site?here is the 2 pieces of code that generated the results::: function display_outfit_stats_total_score() { global $outfit_id; $ApiLink = "http://census.daybreakgames.com/s:egrazziani/get/ps2-beta/outfit/" . $outfit_id . "?c:resolve=member_character(experience.score)"; $json_decode = (json_decode(file_get_contents($ApiLink), true)); $output = $json_decode["outfit_list"]; $total_score = "0"; foreach ($output as $key => $value) { if (isset($output[$key]["members"])) { $members[$key] = $output[$key]["members"]; foreach ($members[$key] as $row) { $total_socre = $row['experience']; if (isset($row['experience'])) { foreach ($total_socre as $expier) { $score = $expier['score']; $total_score += $score; } } } } echo number_format($total_score); } } function display_outfit_stats_total_damage_given() { global $outfit_id; $ApiLink = "http://census.daybreakgames.com/s:egrazziani/get/ps2-beta/outfit/" . $outfit_id . "?c:resolve=member_character(stats.damage_given.value)"; $json_decode = (json_decode(file_get_contents($ApiLink), true)); $output = $json_decode["outfit_list"]; $total = 0; foreach ($output as $key => $value) { if (isset($output[$key]["members"])) { $members[$key] = $output[$key]["members"]; foreach ($members[$key] as $row) { $damage_given = $row['stats']['damage_given']['value']; $total += $damage_given; } } echo number_format($total); } }
     
  7. shinigai

    shinigai Guest

    I guess my woe's are only felt else where :p Planets side universe api also feeling sluggish :)
     
  8. FeiXue

    FeiXue Guest

    Depending on the size of the outfit queried you're asking for quite a large dataset which both takes time to gather and transmit. Then you do the opposite extreme and ask for two details of each character using two API calls.

    file_get_contents and in general all functions that depend on outside source of data should have error checking wrappers. Even if API server were up that call could have exceeded your script execution timeout.

    You can't expect to use such service as realtime data source. Build a database cache then use c:limit with c:start to retrieve partial data sets and store them in local cache. Have automated scripts do this independent of webpage that's using the data.

    Finally, go through data and categorize it by how often it changes then build retreiving mechanism around that. You don't have to query character's BR every 10 minutes or its outfit rank every hour.

     
  9. Dedith

    Dedith Guest

    I like to use curl myself...

    $url = sprintf(" == 0) { // handle error of no data returned} else { // process data, and generally use isset() to check if it exists}

     
  10. Dedith

    Dedith Guest

    I completely agree here.  I do a query just getting the timestamp of something to see if it changed since I last did, then i check it against my cached copy in the db.

     
  11. shinigai

    shinigai Guest

    cool :) thanks guys for all the help! I am building a script to import the info into mysql to cache all the info and then update it periodically 

    if you guys have any tips for doing such a feat let me know thanks! <img src="/station/images/smilies/283a16da79f3aa23fe1025c96295f04f.gif" border="0" /> you are all great help!

     

Share This Page