简体   繁体   中英

include_once php file or fopen txt?

I have a big database proccess when page loads.

So I decide save processed database results in a txt file. and update them per hours in day.

So I know two method:

save them in a php file and call them like this:

system create a php file (via php),save datas in it and call them like this:

include_once("myfile.php");

another method save in a txt file and call them like this:

$myfile = fopen("myfile.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("myfile.txt"));
fclose($myfile);

I want to know wich method is faster or better?

What you are doing is caching a query result. If it is a very simple website, then this solution might be enough, but it will not scale well if amounts of data or complexity increases. Just FIY, you can use database to cache generated data too.

Unless your queries are performing inherently heavy calculations or joins, I would try to optimize the queries first before implementing caching. Both database queries and reading files access filesystem, and filesystems are inherently slower than true data caching solutions, such as Redis.

I'm not even sure what your question was, but I hope i've helped to shed some light on your situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM