doune1000 2012-07-25 20:56
浏览 48
已采纳

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

  • 写回答

1条回答 默认 最新

  • dongzouqie4220 2012-07-25 21:02
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?