PHP SQL Select语句VS保存到文件服务器加载

I have a app that loads some json from my php web service. This information may update every hour or so.

Currently every time a user hits the url i requery the database and present the json results.

I am now getting a few more users and want to minimise the load on the server.

Is it better to run this way or run a cron job and read and write from a file.

i.e The cron does the query and saves to a local file. When the user hits the url i then read the query.

I have tested both and load time is about the same but i wonder how this effects the sever overall?

I don't think memchace is any good due to the amount of data returned.

Any tips or ideas would be great

Dan

It is much better to create a plain text file that is fetched with your json data in it.

The serverload is much higher if the webserver has to invoke a script (and possible queries too to the database). Many processes are involved in this, even though good webservers try to optimize as much as possible.

A plain file is fetched without much overhead, so go for the cronjob to update the file, as let your app simply request that file, like you suggested yourself.