Apart from cron
Moderator: General Moderators
-
oneofthelions
- Forum Newbie
- Posts: 14
- Joined: Tue Oct 27, 2009 2:41 am
Apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?
Re: Apart from cron
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.
But cron's easier, and if you can't run cron I doubt you'd be allowed a background process.
-
oneofthelions
- Forum Newbie
- Posts: 14
- Joined: Tue Oct 27, 2009 2:41 am
Re: Apart from cron
I need to run apart from cron, it is a script...
I am not sure if Godaddy allows me chmod any file... need more clarification.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
}
?>
Re: Apart from cron
If you have FTP or SSH access then you can. If not, you probably can some other way.oneofthelions wrote:I am not sure if Godaddy allows me chmod any file... need more clarification.
-
oneofthelions
- Forum Newbie
- Posts: 14
- Joined: Tue Oct 27, 2009 2:41 am
Re: Apart from cron
My script obviously did not run the next time...PLEASE CORRECT ME
OR..could I do?
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
}
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()
}
-
oneofthelions
- Forum Newbie
- Posts: 14
- Joined: Tue Oct 27, 2009 2:41 am
Re: Apart from cron
[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
Can this user specific script be run as cron??
.....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