如何在代码中实现cron(php)?

Maybe It's a stupid question, but I didn't find answer. I use a web-hosting startlogic.com. I asked employee about cron. They told me that they only have a feature in the control panel called "Schedule jobs" where I can manually put the job. But I need to do this from my web-application. For example, when I push button, I will receive a email notification after 1 month. How to implement this using php? Can my web-hosting provider do this or I need to change provider (if yes, what will you recommend?)

Thanks in advance.

  1. Make a PHP script called cron.php (outside of your web root if possible).

  2. Set this to run regularly under "Schedule Jobs"

  3. Every time cron.php runs, it checks a database of jobs to see if any are due yet.

  4. If any are due, they are run.

  5. Once run, they are marked as such.

  6. To add new jobs to the list, just add a new row to the database with the details of the job and the due date.

You could have one PHP script, that gets run say once an hour. In this script you could then implement your own cron-like functionality, say reading a database of cronjobs and executing them.

If you don't care about the exact time, you can check with each pageload (or every first an hour) your database, if there are jobs that need to be executed.

This way the cron will not be executed exactly after a month, but with the next page load after a month, which will most likely occur soon.