开发者

Run a code after specific time in php

开发者 https://www.devze.com 2022-12-30 04:08 出处:网络
I need to run a code again and again on server after a f开发者_开发知识库ixed time. Is it possible to do so?

I need to run a code again and again on server after a f开发者_开发知识库ixed time. Is it possible to do so?

I am using PHP.


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.


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


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号