Ticker system

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hammer136
Forum Commoner
Posts: 29
Joined: Sat Mar 19, 2005 12:18 pm

Ticker system

Post by Hammer136 »

Hi

For my web site i need some sort of ticker system that refreshes the page and does some background work every 10 minutes. Some people have told me to use cron jobs but i dont have a linux server and others say to use sheduled tasks in windows. Is there no code to do this?!?

Any help appreciated

Hammer
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You want the web page to refresh or you want the server to refresh a database or something.

The latter is cron, but just refreshing the page is not.

You could:

a) Use a meta refresh which redirects to itself
b) Use a javascript timer which reloads the page after x seconds
c) Do both

Meta refresh;

Code: Select all

<!-- this goes between <head> and </head> -->
<meta http-equiv=&quote;refresh&quote; content=&quote;600; thispage.php&quote;>
or if you're using PHP the genric way to do it so you don';t have to specify the page name would be:

Code: Select all

<!-- this goes between <head> and </head> -->
<meta http-equiv="refresh" content="600; <?= $_SERVER['PHP_SELF']; ?>">
or using javascript:

Code: Select all

&lt;script language=&quote;javascript&quote; type=&quote;text/javascript&quote;&gt;
window.setTimeout(function() { window.reload() }, 600000);
&lt;/script&gt;
Hammer136
Forum Commoner
Posts: 29
Joined: Sat Mar 19, 2005 12:18 pm

Post by Hammer136 »

Well basically both. Im in the process of making a game and have the large majority done but in my text based game i have seasons that rotate every 10 minutes. So i have a database setup with the seasons and it need to look at it and check if it needs to change. Also i have a battle tick system so that it takes x amount of ticks to get to an opponent.
So all i need is to set up a ticker system, and i can do the rest.

Thanx

Hammer
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Crons seems like a very viable option for changing the seasons every ten mins.

Otherwise, I'd just put a time of last season change in the DB, then refresh the page which checks if it has been more than ten mins since the last season change. You can do this using the date() functions. The unix timestamp that date() works with is recorded in seconds so the calculation shouldn't be too hard.

I think sessions will help you keep a count of the number of ticks.

http://www.php.net/sessions

You could then have some conditionals that see how many ticks have been made and then do some DB query only if the conditions you give are satisfied.
Hammer136
Forum Commoner
Posts: 29
Joined: Sat Mar 19, 2005 12:18 pm

Post by Hammer136 »

Thanks for your help

Just 1 last thing though, how do i use crons? As i know nothing about it.

Thanks again
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Cron is just scheduling a task to run every so many seconds, minutes or hours. It's just that you schedule a php script to run....

Your host probably has something set up for you to do it easily.

If your host runs CPanel then there is an icon for Cron if they allow it.

If you are doing it yourself I don't know the *nix way to do it but on windows it very straightforward.

In windows...

1. Go to control panel
2. Click on scheduled tasks
3. Choose to set a new task
4. As the program to run just type "c:\your\path\to\php.exe c:\your\path\to\the\php\script.php"
5. It can be scheduled to run every ten minutes somewhere in the advanced options of shceduled taks.

Hope this helps... sorry if it is a *nix system but I'm sure somebody else in here could help you on that one :wink:
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Hammer136 wrote:Well basically both. Im in the process of making a game and have the large majority done but in my text based game i have seasons that rotate every 10 minutes. So i have a database setup with the seasons and it need to look at it and check if it needs to change. Also i have a battle tick system so that it takes x amount of ticks to get to an opponent.
So all i need is to set up a ticker system, and i can do the rest.

Thanx

Hammer
I work on and contribute to multiple php games, and the prevailing standard is to use crontabs for such events.

You setup a page, and have the crontab 'poll' that page at regular intervals.

Thats probably the ideal for what you are asking for..
Post Reply