0

I would like to make a script that would run all the time at server or at least at certain times, because I have some actions I want to do at certain times. For now I have a script that refreshes every 1 second and that is good, but only in case when user is on the site. When site is not opened, it doesn't work. Any solutions?

EDIT: What would be better choice of suggested solutions, cron job or PHP daemon?

2 Answers2

2

If you're on a Linux system, then you could use the CRON Daemon which allows users to execute scripts or commands (or groups of commands) at a specified time.

You would schedule a CRON event using Crontab (CRON Table). Crontab is a file which contains the list of all cron jobs and at what time they're due to run (think of it as a schedule)

Creating an entry into Crontab has it's own peculiar syntax beyond the scope of this post, but for more information.

Paul McLoughlin
  • 2,279
  • 2
  • 18
  • 24
  • 1
    Thanks for posting your answer! Please note that you should post the essential parts of the answer here, on this site, or your post risks being deleted [See the FAQ where it mentions answers that are 'barely more than a link'.](http://stackoverflow.com/faq#deletion) You may still include the link if you wish, but only as a 'reference'. The answer should stand on its own without needing the link. – Taryn Mar 04 '14 at 20:43
0

You can set up your PHP to run as a daemon. I've implemented this for some of my scripts that need to check for data constantly.

I used Upstart for this job and pretty much followed the path from this post on Stack Overflow:

https://stackoverflow.com/a/16577806/3293987

He also has links to the source where he learned it from.

Community
  • 1
  • 1
Quixrick
  • 3,190
  • 1
  • 14
  • 17