tags:

views:

269

answers:

6

i need to run a code again and again on server after a fixed time. is it possible do so. iam using php.

+3  A: 

You can create scheduled tasks through CronJobs.

Also have a look through this article to run PHP scripts through Cron.

So basically what you will have to do is create the script you want to run via PHP and using the above articles create a Cron for the specific interval.

Russell Dias
+1  A: 

You can use a Cron job to call a PHP script at certain intervals.

alex
can i do thisfunction doSomething(){//do sleep(3600)doSomething()}
Praveen Prasad
@Praveen Yes, but your script will hang for that amount of time. Not recommended.
alex
+1  A: 

What you need is called Cron

From the Article

Cron is very simply a Linux module that allows you to run commands at predetermined times or intervals. In Windows, it’s called Scheduled Tasks. The name Cron is in fact derived from the same word from which we get the word chronology, which means order of time.

Soufiane Hassou
A: 

use cron job and if you want to keep the codes of a page to run continously you can use header reload initially in your page

header('Refresh: 3; url=index.html');

this is going to reload the same page again and again in 3 seconds, but if you want to run a code without user opening a certain page then cron job is your solution

Starx
A: 

Please use Cron job to accomplish the task. You may execute php cli to start the PHP engine in command-line mode. You can modify a setting text file to instruct Cron job when to execute.

xdallen
A: 

In your hosting control panel you should have an option to set a Cron Job that can be used to run a PHP script at any interval. The command you need to use should look like this:

/usr/bin/php -q /home/USERNAME/public_html/PathToFile

The cron setup will allow you to setup how often your script will run, every minute, 5 mins, hour, daily, weekly, etc.

Martin