Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- #Class cronjobs externo
- #Alan Cordeiro
- #3/04/2010
- @Banco de Dados:
- /*
- CREATE TABLE IF NOT EXISTS `urls` (
- `id` int(12) NOT NULL AUTO_INCREMENT,
- `url` varchar(512) NOT NULL,
- `time` int(128) NOT NULL,
- `next` int(128) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
- */
- @Exemplo Inserir Tarefas:
- /*
- $cron = new cronjobs;
- $cron->insertUrl($_POST['url'],$_POST['intervalo']);
- */
- class cronjobs{
- private $dbuser = 'root';
- private $dbpass = '';
- private $db = 'cronjobs';
- public function __construct(){
- $sql = mysql_connect('localhost',$this->dbuser, $this->dbpass)or die(mysql_error());
- mysql_select_db($this->bd,$sql)or die(mysql_error());
- $this->sql = $sql;
- }
- public function insertUrl($url,$time){
- $searchUrl = mysql_query("SELECT url FROM urls WHERE url='".$url."'",$this->sql);
- if(mysql_num_rows($searchUrl) == null){
- $next = date('i',time()+($time*60));
- mysql_query("INSERT INTO urls (url,time,next) VALUES('".$url."','".$time."','".$next."')",$this->sql);
- }else{
- mysql_query("UPDATE urls SET time='".$time."' WHERE url='".$url."'",$this->sql);
- }
- }
- public function exec(){
- $searchUrl = mysql_query("SELECT * FROM urls WHERE next='".date('i')."'",$this->sql);
- while($row = mysql_fetch_array($searchUrl)){
- if(date('i') == $row['next']){
- $next = date('i',time()+($row['time']*60));
- mysql_query("UPDATE urls SET next='".$next."' WHERE url='".$row['url']."'",$this->sql);
- $curl = curl_init();
- curl_setopt($curl,CURLOPT_URL,$row['url']);
- curl_setopt($curl,CURLOPT_FOLLOWLOCATION, true);
- curl_exec($curl);
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement