Temporary events with php / MySQL

I need to change the value in the table after a while. My current method is as follows:

  • insert end time for waiting period in table
  • when the user loads a page asking for the value to be changed, check if the current> = end time is
  • if so, change the value and delete the end time field; if it is not, do nothing

This will be the main feature on the site, so efficiency is the key; keeping in mind, you can probably see a problem with the way I do it. The same piece of code will be called every time someone accesses a page that needs information.

Any suggestions for improvement or better methods are welcome, preferably in php or perl.

In response to the answers to cron's work: Thank you, and I would like to do something similar if possible, but problems with the hosts are problems. Since this is the main part of the application, it cannot be limited.

+4
source share
5 answers

why not use cron to update this information behind the scenes? this way you download checks for every page hit and you can actually plan the time to meet the requirements for your application.

+5
source

Your decision sounds very logical since you do not have access to cron. Another way is to save the value in a file, and at the next page load, check when it was last modified (filemtime ("checkfile.txt")), and decide whether it needs to be modified again. You should check the performance for both methods.

+3
source

Can you use the cron job to periodically check each field in the database and update this path?

Most of this is how often updates are required. Many shared hosts limit the frequency of cron checks, for example, no more than every 15 minutes, which may affect the application.

+2
source

You can use some kind of trigger for every page load. I really don't know how this will affect performance, but maybe someone else can shed some light.

+1
source

If performance really starts to be a problem (which means a lot more than you probably understand), you can use memchached to store information ...

0
source

Source: https://habr.com/ru/post/1277090/


All Articles