Page 1 of 1

Apart from cron

Posted: Tue Oct 27, 2009 5:12 pm
by oneofthelions
I need to run a php file every one hour. Is there any other solution apart from cron job?

Re: Apart from cron

Posted: Tue Oct 27, 2009 5:39 pm
by requinix
Could make a daemon for it...

But cron's easier, and if you can't run cron I doubt you'd be allowed a background process.

Re: Apart from cron

Posted: Sat Oct 31, 2009 1:10 am
by oneofthelions
I need to run apart from cron, it is a script...
Someone gave me this solution..

Make a file called "time.db" and CHMOD it as 0777
PHP Code:
<?php
// name of your file
$myFile="time.db";
$time=file($myFile);
if(time()-3600 > $time[0]){
// an hour has elapsed
// do your thing.

// write the new timestamp to file
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, time());
fclose($fh);
}
else{
// it hasn't been an hour yet, so do nothing
}
?>
I am not sure if Godaddy allows me chmod any file... need more clarification.

Re: Apart from cron

Posted: Sat Oct 31, 2009 1:26 am
by requinix
oneofthelions wrote:I am not sure if Godaddy allows me chmod any file... need more clarification.
If you have FTP or SSH access then you can. If not, you probably can some other way.

Re: Apart from cron

Posted: Sat Oct 31, 2009 3:58 am
by oneofthelions
My script obviously did not run the next time...PLEASE CORRECT ME

Code: Select all

 
require_once("includes/connection.php");
 
    $query = mysql_query("SELECT lastRun FROM time") or die(mysql_error());
    if(mysql_num_rows($query)!=0)
    {
        while($row = mysql_fetch_array($query)) 
        {
        $TimeRun = $row['lastRun'];
        if ($TimeRun + 3600 < time())
            {
            $to_email = "salman_ahad@yahoo.com"; 
            $subject = "test script";
            $message = 
            "Time : Running"; 
 
            mail($to_email, $subject, $message); 
            $TimeRun = time();
            $querypost = mysql_query ("UPDATE time SET lastRun = '$TimeRun'");
            }
        }
    }
    else{
    //nothing
    }
 
OR..could I do?

Code: Select all

 
function first(){
//All my code
 
sleep(3600);
call function second()
}
 
function second(){
//All my same code as above
 
sleep(3600);
call function first()
}
 
 

Re: Apart from cron

Posted: Sat Oct 31, 2009 4:45 pm
by oneofthelions
[quote author=PFMaBiSmAd link=topic=274543.msg1300228#msg1300228 date=1256993285]
.....cron job on your godaddy hosting
[/quote]

any cron job allows us to run a php file at specific time...but this is what I am trying to do

Code: Select all

 
//test.php
 
//users table contains multiple users
 
//message table contains multiple messages
 
$user = mysql_query("SELECT * FROM users") or die(mysql_error());
$message = mysql_query("SELECT * FROM message") or die(mysql_error());
 
//...guide me for rest of the code
 
//Every user should be sent a message every one hour. Also the message which was not sent to any user.
 
//Lets say 
user-1 was sent a message-23 at 01:02:03  // user-1 shld receive the next message in queue after one hour
user-2 was sent a message-40  at 20:22:00  // user-2 shld receive the next message in queue after one hour
...
user-n was sent a message-78 at 12:30:10 // user-n shld receive the next message in queue after one hour
 
 
Can this user specific script be run as cron??