Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP JSON Request Overload
    primarykey
    data
    text
    <p>On my <a href="http://www.nbws.co.uk" rel="nofollow">website</a> I have a piece of php code that downloads some JSON and updates the site with what it says. </p> <p>My site however is becoming more and more popular and I am close to reaching the limit on my api key. The data however only updates every ten minutes so I was thinking there must be a way to only allow the script to run every ten minutes but still produce the required text.</p> <p>My php code: </p> <pre><code>&lt;?php $json_string = file_get_contents("http://api.wunderground.com/api/MYKEY/conditions/q/pws:IENGLAND469.json"); $parsed_json = json_decode($json_string); $time = $parsed_json-&gt;{'current_observation'}-&gt;{'observation_time'}; //Take obs time string $windmph = $parsed_json-&gt;{'current_observation'}-&gt;{'wind_mph'}; //take wind speed $gustmph = $parsed_json-&gt;{'current_observation'}-&gt;{'wind_gust_mph'}; //take gust $dir = $parsed_json-&gt;{'current_observation'}-&gt;{'wind_dir'}; $degs = $parsed_json-&gt;{'current_observation'}-&gt;{'wind_degrees'}; $windknots = round($windmph/1.15078,1); //rounds and converts $gustmphflt = (float) $gustmph; //float to string $gustknots = round($gustmphflt/1.15078,1); //round and convert if($windknots &gt;27){ echo "&lt;div class='alert alert-danger'&gt;&lt;strong&gt;Wooooah!!&lt;/strong&gt; Be careful super strong winds of ${windknots}&lt;/div&gt;"; } if ($windknots &gt;16 AND $gustknots &gt; 1.7*$windknots ){ echo "&lt;div class='alert alert-danger'&gt;&lt;strong&gt;Wooooah!!&lt;/strong&gt; Be careful it's gust out there!!&lt;/div&gt;"; } if($degs&gt;80 AND $degs&lt;200){ echo "&lt;div class='alert alert-danger'&gt;&lt;strong&gt;Be Careful Offshore Wind!!&lt;/strong&gt; The wind is offshore, blowing from ${dir}!&lt;/div&gt;"; } ?&gt; </code></pre> <p>and:</p> <pre><code>&lt;?php echo "&lt;p&gt; &lt;!--From the ${dir} at--&gt; ${windknots} Knots gusting to ${gustknots} Knots&lt;br&gt;${time}&lt;/p&gt;"; //print ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload