One question and recommendation to choose best way

I have some game system in php / mysqli / jquery.
The game play every 15 min, so every 15min script update my DB.
When quest,user or search robot come to website or just someone do refresh page, the last results shows from file cache system, the jquery send reg. to the php file.
It work like in image

Now i want optimize more, need best way.

Here is example how it work now (php file)

header ('Content-Type: text/html; charset=utf-8');
function balls_results(){
<script type="text/javascript">$(this).ready(function(){var $ball=$('#balls > div'),diameter=$ball.height(),perimeter=Math.PI*diameter,n=$ball.length,i=0,itv;itv=setInterval(function(){if(i>n)clearInterval(itv);rotateBall(942-(diameter*i));i++;},700);function rotateBall(distance){console.log(distance);var degree=distance*360/perimeter;$ball.eq(i).css({transition:"2s cubic-bezier(1.000, 1.450, 0.185, 0.850)",transform:'translateX('+distance+'px)'}).find('div').css({transition:"2s cubic-bezier(1.000, 1.450, 0.185, 0.850)",transform:'rotate('+degree+')'});}});</script>
$latest_ctime = 0;
$latest_filename = '';    
$path = "/path/public_html/cache/system/";
$d = dir($path);
while (false !== ($entry = $d->read())) {
  $filepath = "{$path}/{$entry}";
  if (is_file($filepath) && filemtime($filepath) > $latest_ctime) {
    $latest_ctime = filemtime($filepath);
    $latest_filename = $entry;
$fileres = "/path/public_html/cache/system/".$latest_filename."";
$b = unserialize(file_get_contents($fileres));$results = $b[1];
echo "<div class=\"ball red\"><div><span>".implode("</span></div></div><div class=\"ball red\"><div><span>", explode(",", $results))."</span></div></div>";
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo "<br /><div id=\"balls\">";
return balls_results();
echo "</div>";

Now: I have so many CP used in hosting for this system, need other way, i can take results from DB but it is bad idea. If i will cache to memory (with Memcache/Memcached) , it will update results when i don’t needed. Because i have timer in the website, when time = 0, jquery system refresh some div and show new results.

To understand just come to see how it work (and whats happend when time will be 00:00)

Thanks for help.

So… if you’re going to store the data in a file, you wouldnt save it in the database as well, because the database will never get read?

I save in database and file. Before, when i started, all gamee worked from db. Database it is for history results, (work with memcached), i don’t wanna take results from db now, because all other info website taked from their. All problem it’s Jquery script (But without this structure, my site is different from other), when time is 00:00, give new numbers in balls. Maybe there is an option, to start I would like to know that I will bring results with less low-load, using a file system (file_get_contents) or through memcache. How can I check and tested ? Thanks (and sorry for my bad english)

So you say that you have “many CP used in hosting”… i’m not sure what CP means in this context; Are you saying that multiple servers will be connecting to one server to get the information?

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