Jump to content

Crons.


seany123

Recommended Posts

I dont know if this is in the correct sections but ill ask here anyway.

 

on my website i have a cron page in place to everytime the page is loaded and its in X amount of time the page update my database.

 

the problem is, if i dont have anyone online to load the page then the cron wont happen and it obviously doesnt back date... (so it only runs once)

 

is there any programs or websites i could use which would stay constantly on that page? refreshing every couple seconds...

 

or does anyone have any ideas of how i could get this to do it when i have no people online.

Link to comment
Share on other sites

  • 3 weeks later...

What browser based game are you making?

 

And i have a browser based game. I have also the page which updates the user.

 

This script does not need to perform every minute. How ever what it does is. When some one clicks after like 10 minute's. It all add's up so when he click's it does not remove 1 it remove's all 10.

 

Try this script:

 

<?php

$result = mysql_query("SELECT * FROM `updates` WHERE `name` = '1min'");
$result = mysql_fetch_assoc($result);
$hla    = time() - $result['last'];

if($hla > (60))
{
$n = floor($hla / 60);
$hos = mysql_query("SELECT userid FROM `users` WHERE `hospital` <> 0");
$hos = mysql_num_rows($hos);
$jail = mysql_query("SELECT userid FROM `users` WHERE `jail` <> 0");
$jail = mysql_num_rows($jail);

$hospital = (1 * $n);
$jail     = (1 * $n);

$query_hos = sprintf("UPDATE users SET hospital = hospital - %u WHERE hospital <> 0", $hospital);
$query_jail = sprintf("UPDATE users SET jail = jail - %u WHERE jail <> 0", $jail);

mysql_query($query_hos);
mysql_query($query_jail);

$time = time();
mysql_query("UPDATE `updates` SET `last` = ".$time." WHERE `name` = '1min'");
$floor = $time - (floor($time / 60) * 60);
if($floor > 0)
{
	$newUpdate = time() - $floor;
	mysql_query("UPDATE `updates` SET `last` = ".$newUpdate." WHERE `name` = '1min'");
}
}

?>

 

Your table structure:

 

Table => updates => name

                            last

 

Then insert into updates:

 

Name => 1min

Last  => unix_timestamp();

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.