PDA

View Full Version : Cron script


The_Return
08-24-2009, 08:03 AM
1) Project Details: Cron script to check database

2) Payment Amount: $10

3) Payment method: Paypal

ok updated the script a bit now the problem is if you loop the aim parts it stops working I also concluded a working script at the bottom if you can help me pm.


<?php
ob_implicit_flush(true);
include("aimclassw.php"); //Toc

//Database connect

$query3 = "SELECT COUNT(*) as num FROM jobs WHERE status = '0'";
$total_jobs = mysql_fetch_array(mysql_query($query3));
$total_jobs = $total_jobs[num];

if ($total_jobs > 0) {

$b = new Aim("screenname","password",4);
$b->registerHandler("Config","onConfig");
$b->registerHandler("Nick","onNick");
$b->signon();
sleep(3); // delay after sign in

while(!defined("CAN_SEND")){
$b->receive();
}

//check if their are jobs
$query = "SELECT * FROM jobs WHERE status = '0'";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)) {

$message = $row['message'];
$hostid = $row['hostid'];

//select all the aims with the host id given
$q = "SELECT aim FROM friends WHERE hostid = '$hostid'";
$re = mysql_query($q) or die(mysql_error());

while($r = mysql_fetch_array($re)){

$aim = $r['aim'];

$b->sendIM("$aim","$message");
sleep(3);

}//End while loop

$query2 = "DELETE FROM `jobs` WHERE `message` = '$message' AND `hostid` = '$hostid'";
$result2 = mysql_query($query2);

} //end loop

function onConfig()
{
define("CAN_SEND",1);
return;
}

}// end if
?>



heres an example of a working version tho it can not grab the host id or the message so I have to manually put it in


<?php
ob_implicit_flush(true);
include("aimclassw.php"); //Toc

//Database connect

$hostid = "c9723097991b56826b1b854f61c177f3";
$message = "This is a test notification";

//Grab them screen names
$query = "SELECT aim FROM friends WHERE hostid = '$hostid'";

$result = mysql_query($query) or die(mysql_error());

$b = new Aim("screenanme","password",4);
$b->registerHandler("Config","onConfig");
$b->registerHandler("Nick","onNick");
$b->signon();
sleep(3); // delay after sign in


while(!defined("CAN_SEND")){
$b->receive();
}

while($row = mysql_fetch_array($result)){

$b->sendIM($row['aim'],"$message");
sleep(3);

}//End while loop

function onConfig()
{
define("CAN_SEND",1);
return;
}

?>

it career
08-24-2009, 10:16 AM
What is the work ? - just adding this php file in your cron job list ?

The_Return
08-24-2009, 05:04 PM
Just to fix my script so it does this

First checks for jobs in the database if so continue

Next it grabs the row with message and hostid

Then gets all the screen names with host and sends out message (That part is working fine)

Deletes the job because it is finished

Goes to next job if their is any