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
Ticker system
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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;
or if you're using PHP the genric way to do it so you don';t have to specify the page name would be:
or using javascript:
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="e;refresh"e; content="e;600; thispage.php"e;>Code: Select all
<!-- this goes between <head> and </head> -->
<meta http-equiv="refresh" content="600; <?= $_SERVER['PHP_SELF']; ?>">Code: Select all
<script language="e;javascript"e; type="e;text/javascript"e;>
window.setTimeout(function() { window.reload() }, 600000);
</script>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
So all i need is to set up a ticker system, and i can do the rest.
Thanx
Hammer
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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.
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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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
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
I work on and contribute to multiple php games, and the prevailing standard is to use crontabs for such events.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
You setup a page, and have the crontab 'poll' that page at regular intervals.
Thats probably the ideal for what you are asking for..