You have clients that are each invoking a request to some external API and the server is dealing with each of these requests. You can force the client to make the request to the Google API if that is the case, can you not?
Take a look here too: https://codelabs.developers.google.com/codelabs/lovefield/index.html?index=../../index#0
Thing is, i'm unsure of how this would work if it even does when it comes to multiple users accessing the data, I figure it to be something more like a cookie but I may be wrong? It still seems like it would bring the benefits in terms of offline data storage and also in that link it's dealing with monitoring stock data so is applicable...
However, without creating a client side application and working with what you have got, you'd still need to cache the data on the server side...
So, instead of the website querying the Google API directly for each request, implement a cache for the results so that when your server gets 10 clients all making the same query at once, it will fetch and store the data once then realise that the other 9 are the exact same thing so will return the cached result instead of querying the Google API again?
Where does it store that data? Who cares, sqlite is fine if its just a small thing but dont query the Google API 100 times is my point... I think that is the problem that you're facing.
That sounds to me like a scalable solution, you could have many users making use of this and its not going to get slower and slower each time someone else joins in?
Close, look if I could use a DB it would have been a walk in a park this is what I have in my offline setup
Cronjob:
PHP:
//Stock Watch
// set quotes
$quotes = array("CLI", "CFR", "VOD", "DSY", "CCO", "MFL", "SHP", "TAS", "MTN", "SYG", "SGL", "SNV");
foreach ($quotes as $quote) {
$url = "http://www.bloomberg.com/markets/api/quote-page/$quote:SJ";
$json = file_get_contents($url);
$json = json_decode($json);
$company = $json->basicQuote->name;
$price = $json->basicQuote->price;
$percentage = round($percentage = $json->basicQuote->percentChange1Day, 2, PHP_ROUND_HALF_UP);
$modified_time = date("Y-m-d H:i:s");
// Update the quotes in the Database
$sql = "UPDATE stock_history SET price = :price, percentage = :percentage, time = :time WHERE company = :company";
$statement = $db->prepare($sql);
$statement->execute(array(':company' => $company, ':price' => $price, ':percentage' => $percentage, ':time' => $modified_time));
}
//Market News RSS Feed
$rss = new DOMDocument();
$rss->load('http://feeds.24.com/articles/Fin24/Markets/rss');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 5;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$pattern = '(Fin24\\.com)';
$replacement = '';
$a = preg_replace($pattern, $replacement, $title);
$re1='.*?'; # Non-greedy match on filler
$re2='(\\|)'; # Any Single Character 1
$replacement_2 = '';
$title = preg_replace("/".$re1.$re2."/is", $replacement_2, $a);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
$unique_hash = hash('SHA256', $title.$link);
$statement = $db->prepare("INSERT IGNORE INTO market_feed (`title`, `description`, `link`, `date`, `unique_hash` ) VALUES (:title, :description, :link, :date, :unique_hash)");
$statement->execute(array(':title' => $title, ':description' => $description, ':link' => $link, ':date' => $date, ':unique_hash' => $unique_hash));
}
Then whenever a user hits the site I merely read back the data:
PHP:
<?php
//Select Stocks to show
$sql = "SELECT company, price, percentage FROM stock_history";
$statement = $db->prepare($sql);
$statement->execute();
//Display the stocks
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
echo "<div class=\"stock"; if ($row["percentage"] >= 0) {echo ' green';} else { echo ' red';} echo "\" id=\"stock-1\">
<span class=\"symbol\">"; echo $row["company"];
echo "</span>
<span class=\"change\">";if ($row["percentage"] > 0) {echo '+';} else { echo '';} ;
echo $row["percentage"];echo "%</span>";
echo "<br>";
echo "<span class=\"price\">"; echo $row["price"]; echo " cents</span>";
echo "</div>";
}
?>
The above is what I want to implement into PW, but the forum software is quite a headache to work with very convoluted, but getting off topic.
Point is I want to do what I did there, but without a database.