tags:

views:

50

answers:

5

So... for example I want to add to 1 five every 5 minuts (1 is in the DB)... With out direct calls from users....

So... How to make PHP code work without direct calls (on some kind of timer)?

A: 

If I understood you correctly, CRON is what you're looking for (google it)

radex
+1  A: 

build a script which does what you need to do. and call it via crontab in the needed interval but make sure its not callable from a user or searchengine.

see http://www.unixgeeks.org/security/newbie/unix/cron-1.html for more information on cron

a typical call could look like:

*/5 * * * *      lynx -source http://yourhost.com/yourscript.php >/dev/null
Rufinus
+1  A: 

Yes configuring a cron job is the correct answer. See the Wikipedia article for the syntax of a cron job.

You simply create a new cron job and let it request the page where the script is. The following cron job requests update.php every five minutes.

*/5 * * * * wget http://www.example.com/update.php

Update

Syntax with wget.

Niels Bom
just to be exact, your cron requests nothing, it tries to execute update.php (which will only work if you set the interpreter in the first line e.g. #!/bin/php)
Rufinus
@Rufinus, you are right, but most of the time I do this with wget (which I added in my update). Your version is more secure btw.
Niels Bom
+1  A: 

If you are unable to schedule cron jobs on your server (as is the case with most cheap hosting solutions), there are some pure php alternatives to run scheduled jobs: phpjobscheduler is one of those alternatives.

Powertieke
A: 

Cron is the obvious suggestion.

If you can only invoke your code via the web (i.e. no command line PHP) then you can call a URL using 'wget' or 'curl' on most *nix boxes.

Unless of course your code sits on a microsoft OS (which is unlikely to have cron available) in which case you can use the 'at' service to do the same thing - and there's a free wget.exe out there somewhere.

C.

symcbean