Designing Repeating PHP/MySQL Task Designing Repeating PHP/MySQL Task php php

Designing Repeating PHP/MySQL Task


You might consider moving from a scheduled task to an update as needed approach. This is fairly easy to accomplish, but there are tradeoffs.

  • Add a datetime field called Last Updated

  • Every time you query the object, check the last updated field for
    "freshness" (in your case, if it was > than 30 seconds ago)

  • If its fresh, send the data to the user.

  • If it isn't fresh, recalculate the data and save it to the database
    (making sure to change the last updated field). Then, send the new
    data to the user.

This will eliminate the need for a scheduled task & get rid of the waste of updating every row. However, it can slow down responses to the user.