I wanted to insert a record to database every minute. this is the my php script.
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$user="ppuser";
$password="ppuserbb";
$database="test";
$host="192.168.1.22";
$names=array('test1','test2','test3','test4');
$id=array_rand($names);
$name=$names[$id];
mysql_connect($host,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$sql="INSERT INTO `crontest` (
`name` ,
`insert_time`
)
VALUES ('".$name."', NOW());";
mysql_query($sql);
mysql_close();
?>
then open the crontab in linux.
run crontab -e on terminal. then add below line to crontab.
*/1 * * * * php /opt/lampp/htdocs/test2/sanjicron.php
- 1st *: Minute (0-59)
- 2nd *: Hours (0-23)
- 3rd *: Day (0-31)
- 4th *: Month (0-12 [12 == December])
- 5th *: Day of the week(0-7 [7 or 0 == sunday])
No comments:
Post a Comment