1

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks so something like the answer to this is the best thing to do? stackoverflow.com/questions/2467945/…
Yes. Use json_encode, and write to a file. Make sure you DON'T pick an extension that might be picked up by the webserver to execute something, like .php. For example: You can write a PHP file with only plain HTML: the receiver of the result won't find any difference, but the webserver invokes the PHP process for no reason at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.