Pausing PHP while Crons run
Moderator: General Moderators
Pausing PHP while Crons run
I've never used crons before, but I have a rather intensive online game job on my plate. I will need to run a good handful of processes each hour, which may take up to 5 minutes at 100% CPU. I am afraid that if users submit an action before the cron has finished, it will interfere with the calculations.
Eg, if member1 has sold goods to member2 before tax is calculated for member2, but after tax has been charged from member1. Tax is charged twice in this case (which doesn't bother me as the admin, but I am afraid of user's finding this sort of loophole).
I plan to write a class that instantiates and calls other classes in order, and the control class will be run every hour, by cron.
* Will PHP queue the initiation of classes after the moment control::execute() starts? (I guess I am asking if PHP can only answer 1 request at a time)
* If not, can anyone direct me to a class or methodology that can handle this for me?
Cheers.
If you are interested in Pure CSS and custom borders without Tables, see http://www.freewebs.com/good-code
Eg, if member1 has sold goods to member2 before tax is calculated for member2, but after tax has been charged from member1. Tax is charged twice in this case (which doesn't bother me as the admin, but I am afraid of user's finding this sort of loophole).
I plan to write a class that instantiates and calls other classes in order, and the control class will be run every hour, by cron.
* Will PHP queue the initiation of classes after the moment control::execute() starts? (I guess I am asking if PHP can only answer 1 request at a time)
* If not, can anyone direct me to a class or methodology that can handle this for me?
Cheers.
If you are interested in Pure CSS and custom borders without Tables, see http://www.freewebs.com/good-code
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Why not just do something SIMPLE. 
If the cron being executed is executing a PHP program on the game site the easy thing to do is...
1. Write a dummy file somewhere in the website when the cron starts executing and then delete it when finished.
or
2. If you are using a database to store configuration variables have a variable called cron_executing. Set it to 1 when the cron starts and the set it to 0 when finished.
Now have an include file called cron_check.php or include the code in a file that is ALWAYS loaded by every page. This code checks to see if the cron_executing config variable is set to 1 or checks to see if the dummy file is present. If either is true then the player is redirected to a page that says the game is executing the hourly cron and they should wait and try again later.
No need to do anything nasty like stopping PHP.
If the cron being executed is executing a PHP program on the game site the easy thing to do is...
1. Write a dummy file somewhere in the website when the cron starts executing and then delete it when finished.
or
2. If you are using a database to store configuration variables have a variable called cron_executing. Set it to 1 when the cron starts and the set it to 0 when finished.
Now have an include file called cron_check.php or include the code in a file that is ALWAYS loaded by every page. This code checks to see if the cron_executing config variable is set to 1 or checks to see if the dummy file is present. If either is true then the player is redirected to a page that says the game is executing the hourly cron and they should wait and try again later.
No need to do anything nasty like stopping PHP.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
redirect all traffic to a "maintenance" page whilst the cron runs, or kill the webserver for the duration of the housekeeping jobs would be a much more simple process.
Put a notification out on the homepage or somewhere telling users the game will be briefly unavailable at 'x' time everyday whilst housekeeping takes place.
Put a notification out on the homepage or somewhere telling users the game will be briefly unavailable at 'x' time everyday whilst housekeeping takes place.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Heck, what a turnout! Thanks for everyone's help!
I spose I will just have to use the maintenance page then. I had thought of that initially, but wondered if there was another way to do it. Players will have to accept that daily maintenance will occur.
Make sure you look at http://freewebs.com/good-code if you are into CSS.
I spose I will just have to use the maintenance page then. I had thought of that initially, but wondered if there was another way to do it. Players will have to accept that daily maintenance will occur.
Make sure you look at http://freewebs.com/good-code if you are into CSS.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I think it's fair enough, especially if you list times on your maintenance pageantz wrote:Heck, what a turnout! Thanks for everyone's help!
I spose I will just have to use the maintenance page then. I had thought of that initially, but wondered if there was another way to do it. Players will have to accept that daily maintenance will occur.
Make sure you look at http://freewebs.com/good-code if you are into CSS.
<side note>
Try not to keep sticking a little ad at the bottom of your posts.... fell free to stick it in your signature though
</side note>
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Actually, he might think about putting a javascript countdown timer somewhere on each page of the game like we do with AATraders. That way every player knows just how far away it is until the next game update.d11wtq wrote:I think it's fair enough, especially if you list times on your maintenance pageantz wrote:Heck, what a turnout! Thanks for everyone's help!
I spose I will just have to use the maintenance page then. I had thought of that initially, but wondered if there was another way to do it. Players will have to accept that daily maintenance will occur.
Make sure you look at http://freewebs.com/good-code if you are into CSS.![]()