See, I have this crontab that updates a mysql database every hour. Then, I have a php file that generates a table with the mysql table contents. Everything works OK, I can see my table and it gets updated just fine. However, I thought of caching that PHP file into an HTML file, because a lot of users access that table and that means a couple of mysql queries for every request for every user. I don't know if that's ok or if it affects my website/database performance. I thought of caching that PHP into an HTML with a cron that would execute 5 min after the normal database update.
So basically, I have a crontab that does something like this:
Code: Select all
<?php
$contents = file_get_contents("http://mywebsite.com/mydata.php");
$FileHandle = fopen("/home/user/public_html/mytable.html", 'w') or die("can't open file");
fwrite($FileHandle, $contents);
fclose($FileHandle);
?>
I was wondering if this is acceptable as "caching". I really have little knowledge about this concept, I know the basics but I'm not sure if I'm doing it right. Or maybe there's a better way. I'm trying not to involve third party applications since I really want to keep learning PHP and its best practices by myself. I have to be honest, I haven't read much about caching and how it should be implemented, but I'm really satisfied with the results of this script I made myself. So now I want an opinion from more experienced developers, am I doing it right? Is there a better way?
Thanks a lot for your help!