Search code examples
cron

How can I start periodical actions server side?


I'm trying to develop a react/redux application and I want to run some server code without needing to trigger an action client side. Right now my needs are to calculate and storage some info in the database and i don't want to run a client that triggers a server action, but in the future i want to make some automatic changes in the database everyday to update my database information based on my previous information. Is there a way to do it?


Solution

  • What you need is called a cronjob. The implementation of this depends mostly on your hosting, but the syntax is always pretty much the same. Let's say you have a file called cron.php which contains the logic for your automatic changes.

    The cronjob would look something like this:

    0 0 * * * location/to/cron.php 
    

    The first two numbers mean at 0 minutes and 0 hours (so 00:00), the following stars mean every day, every month and every weekday. More information about cronjobs here and here.