0

how can I set a scheduled task that run every second on Joomla website?

I saw different extensions but they make only every minute, like minimum threshold. Any idea?

hteo
  • 197
  • 1
  • 2
  • 10
  • Hi, you should probably include som info on what you want to achieve. Running a task every second from joomla is not possible, and probably not what you need anyway. Include info on your goal, you'll get better answers. – jonasfh Jun 03 '17 at 18:11

2 Answers2

2

If you do this with a plain extension you need enough traffic to trigger the task every second. Even then this would be unreliable. The best way to do this is using a CRON job directly on your web server. This CRON job can call a CLI script or a URL on your server.

https://en.wikipedia.org/wiki/Cron

Here are some useful pages to generate the necessary task entry:

https://crontab.guru/

http://crontab-generator.org/

If you want to run it every second you might want to check this:

Running a cron every 30 seconds

There are funny solution like using sleep to increase the cron time resolution. In addition there is a tiny script in one of the answers which might help as well.

Sven Bluege
  • 1,225
  • 1
  • 9
  • 18
1

Using a Joomla extension is not reliable at all, since someone must visit the actual website for the (fake) cron to run. So, this whole cron thing when it's a Joomla extension really depends on the traffic of your website, which makes it very unreliable especially if you are developing a mission critical functionality.

Your best option is to use a Linux cron, which cannot run every second, as the minimum for a cron to run is every minute. Any solution requiring the use of sleep or a for loop is not reliable - especially when you take into consideration that you want to run something every second. All the solutions on the Internet for running a cron every second (or less than a minute) are half baked and completely unreliable. In short, you cannot run a cron every second reliably.

An imaginary solution is to have 60 servers, each server is behind the other by 1 second, and then you run the cron from each of these servers every minute. It is important that all these servers are on the same network to prevent any lag.

itoctopus
  • 3,872
  • 4
  • 28
  • 42