I have a website idea at the moment and I need a timer to be fired every 5 seconds without the users input to check if a remote value (a value on a remote file) has changed to a certain value. Would I need to make a server side C++ script for this? I want to keep it all PHP if I can but if I have to I will make an external script. Would AJAX be able to do this?
-
I want this all without a browser being present at all. – James Heald May 15 '13 at 00:21
-
I love how you want to use AJAX *'without a browser present at all'*. Also, your title says 5 seconds and the text 5 minutes. Which is it? – Niels Keurentjes May 15 '13 at 00:24
-
@Niels The interval doesnt matter. I didnt really mean AJAX exclusively, I just ment is there a way to achieve this in an AJAX fashion. – James Heald May 15 '13 at 00:25
-
Right, now that you edited 5 minutes to 5 seconds all previous answers are invalid. Crons can't run that frequently. – Niels Keurentjes May 15 '13 at 00:25
-
The interval most certainly matters. The standardized way of frequently executing recurring jobs, the `cronjob`, has a maximum frequency of once per minute. – Niels Keurentjes May 15 '13 at 00:26
-
I'd reverse the logic. Have the web server request an external URL when it sees that a value has changed to a certain value. Instead of hammering the server every 5 seconds when nothing has changed. – Reactgular May 15 '13 at 00:27
-
Ahh ok. Yeah its a 5 second refresh interval. cronjob looks like the only option from this point forward. – James Heald May 15 '13 at 00:27
-
I'm downvoting this topic as 'unclear' since it has become a mess with all the previous answers suggesting cronjobs, which cannot run that frequently. I'd recommend you delete it and start over with a new topic that is *correct* and *complete* to begin with. – Niels Keurentjes May 15 '13 at 00:32
-
I cant delete it because there are answers. I apologise for my in-complete thread. Been really tired today. – James Heald May 15 '13 at 00:37
-
Well in advance of the new topic - the only way I see this happening is by creating a `cron` that runs a PHP script every minute, that launches a fire&forget call on another PHP script every 5 seconds, 12 times, before quitting. That should get you close enough to executing the code every 5 seconds. Won't make your hosting provider happy though. – Niels Keurentjes May 15 '13 at 01:44
3 Answers
you can use Cron
( http://en.wikipedia.org/wiki/Cron ) for unix based systems and Windows Task Scheduler
( http://support.microsoft.com/kb/308569 ) for windows

- 2,019
- 2
- 24
- 42
You need to set a cronjob, sort of like:
*/5 * * * * /path/to/php /path/to/my/script.php
Or use remote invocation if you set the script to be callable from the outside as well:
*/5 * * * * /path/to/wget -s http://external.url/to/script.php

- 1
- 1

- 41,402
- 9
- 98
- 136
Is it 5 minutes or 5 seconds? Either way, your question is a bit confusing since you say "without persistent client," so does that mean without any connection from a client? In that case it sounds like a responsibility for a cron job. If your goal is to have a client request this value from your server periodically, then ajax is the simplest solution although websockets may also be viable. You can do this with any server technology with any scripting language on the server side. It's certainly possible with apache+PHP.

- 188,624
- 52
- 326
- 405