 |
|
|
01-27-2009, 06:09 PM
|
PHP Events System
|
Posts: 468
|
I would like to know how i can go about making an events system Where i can order things need doing in order and execute them one after each other.
For example:
12:00 - Play Match 1
12:01 - Play Match 2
12:02 - Update Leagues
I would like to make the site automatically do this without having to do it manually!
|
|
|
|
01-27-2009, 07:21 PM
|
Re: PHP Events System
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
|
|
|
|
01-28-2009, 01:07 PM
|
Re: PHP Events System
|
Posts: 468
|
Yeah but it will be dynamic so not all events happening at any one time!!
I would like a script to be ran and once that one is done the next event in the queue is done and so on"
|
|
|
|
01-28-2009, 02:07 PM
|
Re: PHP Events System
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
You'll have to explain in a little more detail, as it's hard for us to guess based on the description you gave. Are these all scripts that take a long time to execute, over multiple pages, like a game or something? If so, just make a cookie or session that says what game you are on, then when its over, you go to the next one based on what cookie the client computer has on it.
|
|
|
|
01-28-2009, 03:00 PM
|
Re: PHP Events System
|
Posts: 468
|
Ill explain it a little more!!!
Ill have events that need to run script on the server for example! a cron running a football game. these games happen at various different times and i want to make a script that does each event in order and will execute that script and then close the event and start on the next event.
|
|
|
|
01-28-2009, 03:04 PM
|
Re: PHP Events System
|
Posts: 468
|
show theres a waiting list for code to be executed!!!
|
|
|
|
01-28-2009, 03:10 PM
|
Re: PHP Events System
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
Just register them in the database in the order you want them. When the game is over, move on to the next one. I am assuming by this you mean there is one "game" that every one is playing, then everyone who sticks around will play the next "game", etc.
|
|
|
|
01-28-2009, 03:18 PM
|
Re: PHP Events System
|
Posts: 468
|
I already have the matches in order in the database but when i execute the code to run them it goes over the 20 sec limit set on execution so i wanted to execute each one seperatlely!
|
|
|
|
01-28-2009, 03:50 PM
|
Re: PHP Events System
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
Sounds to me like you are putting much too much strain on the server to begin with. If I were you, I would transfer as much of the programming as possible to the browser. After all, JavaScript in the browser is totally event-driven, while PHP on the server is definitely not event driven at all.
|
|
|
|
01-28-2009, 03:58 PM
|
Re: PHP Events System
|
Posts: 468
|
ok. well my match engine is 700 lines long! and will try and run around 50 games every time and it only gets to around 15-20 games a time! (Not Running All Games Required). Each match is played at say 3:00 or 7:45 so if no one is on the site then the games won't run???
|
|
|
|
01-28-2009, 04:04 PM
|
Re: PHP Events System
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
700 lines is nothing, so I imagine that there are some loops of logic that the server is getting hung up on. What happens when you have 1000 people running the same logic together? Your server will crash. However, those 1000 people all have a computer they can contribute to the calculation, each with an engine of its own.
It's a tough problem, I know, especially when there has been so much work that has gone into it already.
Is this your own script, or is it someone else's?
|
|
|
|
01-28-2009, 04:13 PM
|
Re: PHP Events System
|
Posts: 468
|
i wrote it from sratch all by my own! It has quite a few loops and execedes the maximum limit of 20 secs! What happens when no people are active on the site???
|
|
|
|
01-28-2009, 07:02 PM
|
Re: PHP Events System
|
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
So how were you able to write and debug it if you couldn't make it run?
Without looking at all 700 lines, I would offer that it would help to think more modularly. 700 lines is only big if it is one big long procedure with lots of recursive logic. Break apart each task, and find what can exist separate from the whole.
Break it into as many scripts as possible. Only call a script if it is needed. You are going to have to do some rewriting to make this work on people's computers, which is probably going to involve making browsers communicate with the server without a browser refresh (AJAX). This way, certain parts of the logic will only be executed in response to events, which will save a lot of processing on the server.
The smaller you can make each part of the script the better.
Last edited by wayfarer07; 01-28-2009 at 07:09 PM..
|
|
|
|
01-28-2009, 10:14 PM
|
Re: PHP Events System
|
Posts: 801
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
|
ben, wayfarer07 has given you some wise words. STOP OVERLOADING MY POOR SERVER
I doubt what you want to do can be solved with AJAX without completely recoding the website. Try posting all your loops (i.e. whiles) and the relevent variables/querys for them. Put comments next to mysql_fetch_array's to show how many records the query is returning. You will have it instantly pointed out why your script is so slow on such a fast server. If the whole script is a bunch of whiles, take a blank canvas and try to write it again without so many whiles. "and find what can exist separate from the whole"
EDIT: considder echoing a runtime calculation at certain points that are being carried out to see if they the problem or if it is the bits that aren't being carried out. i.e. if after the script has calculated the result for one match, the ruintime is 1 second and you want to run 50 matches, you know your aim is to be to work out the result in <=0.3 seconds to ensure your script will never run over 20 seconds. In reality it should be calculated in much much less say 0.07.
Last edited by mad_willsy; 01-28-2009 at 10:20 PM..
|
|
|
|
01-29-2009, 12:56 PM
|
Re: PHP Events System
|
Posts: 468
|
yeah but in the end could be running 200+ games at a time!
I currently use a cron which runs all ther game indivudual! 1 game = 700 lines!
Ill just have to optimise my code i think!
Last edited by evans123; 01-29-2009 at 12:59 PM..
|
|
|
|
02-03-2009, 11:39 AM
|
Re: PHP Events System
|
Posts: 51
|
Where is the 20 second execution time being imposed, the php.ini? If so, the function set_time_limit can extend that to whatever you want.
However, I would have to agree that every time someone downloads that page, or the script is running you are going to overload your system. An AJAX "engine" might take some time, but I think it would beneficial going forward to distribute the processing across the different users.
|
|
|
|
02-05-2009, 12:45 PM
|
Re: PHP Events System
|
Posts: 468
|
yeah but i have know clue on how to make one in ajax any examples!
|
|
|
|
02-18-2009, 03:37 PM
|
Re: PHP Events System
|
Posts: 14
Name: Andy
|
Here is my suggestion.
1. looking into cron job. Basically, your cron job run every minute or 5 minutes. It checks the database and see whether there is something to do. If yes. do it. However, you need to be careful about it and make sure that the cron job does not run on top of each other. Otherwise, it will run the job multiple time.
2. If you are skilfull enough, you should look into MessageQuestion (Active MQ) or XMPP. However, it is NOT easy. You need to know what you are doing.
__________________
TextLinksDepot.com - Please login or register to view this content. Registration is FREE
|
|
|
|
|
« Reply to PHP Events System
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|