|
Post by Old Shendemiar on Feb 11, 2004 12:42:19 GMT
If i do some game with php-mysql and i want each turn to be calculated automatically at certain time by some separate code at server, what is the easiest/best language to do it? The code would make lot of mysql queries and calculate lot of stuff and then update the database.
|
|
|
Post by sparrowhawk on Feb 11, 2004 12:50:43 GMT
I think that you could do it in most languages, but something like a Perl script called from the cron daemon (I assume your server is Linux?) would probably be best.
But that's where my knowledge ends!
|
|
|
Post by Old Shendemiar on Feb 11, 2004 14:33:24 GMT
What i'm planning on is that several players leave their orders, and at the deadline the game automatically executes all the orders and calcutes new situation.
Other possibility would be that admin executes the End turn script manually at certain time, but that would require effort and i dont like that.
"Perl script called from the cron daemon"
Perl seems to be available to most free hosts, but how exactly the server knows to execute it? Shouldnt it be a constant process that examines occasionally what time & date it is and then calls the code if it's right time?
Other question: what happens if a looooong php is called and stop is hit fractions later in the browser? Does the code execute itself all the way to the end?
|
|
|
Post by sparrowhawk on Feb 11, 2004 14:59:11 GMT
Cron runs in the background (*nix daemons are rather like Windows Services, AFAIK). So you configure Cron to run your script whenever you want (once an hour, twice a day, evry night, etc)
Hitting Stop on the browser will have no effect on a PHP script (I think!) because PHP is server side. So the request has left the client, crossed the web via http, hit the web server, been passed to the PHP processor. By this time the client is well out of it.
What would be visible is that if the PHP script generates html, if you press stop on the browser, this tells the server to stop sending the generated html.
Actually, thinking about it, PHP might pass what it has generated to the web server as a stream, so if it's taking a long time it may be that pressing Stop will tell the webserver to ask the PHP processor to stop. Hmmm, not sure. I'd need to run some tests.
But you should be able to get around this by using output buffering and flushing the contents of the php-generated html stream at the end of your script.
But don't rely on my answers 100%. Maybe David (Frei') can shed mor elight on this?
|
|
Freiegeister
Morkin Member
'Blasphemy is a victimless crime' - Dawkins
Posts: 1,126
|
Post by Freiegeister on Feb 12, 2004 3:17:41 GMT
Cron runs in the background (*nix daemons are rather like Windows Services, AFAIK). So you configure Cron to run your script whenever you want (once an hour, twice a day, evry night, etc) Hitting Stop on the browser will have no effect on a PHP script (I think!) because PHP is server side. So the request has left the client, crossed the web via http, hit the web server, been passed to the PHP processor. By this time the client is well out of it. What would be visible is that if the PHP script generates html, if you press stop on the browser, this tells the server to stop sending the generated html. Actually, thinking about it, PHP might pass what it has generated to the web server as a stream, so if it's taking a long time it may be that pressing Stop will tell the webserver to ask the PHP processor to stop. Hmmm, not sure. I'd need to run some tests. But you should be able to get around this by using output buffering and flushing the contents of the php-generated html stream at the end of your script. But don't rely on my answers 100%. Maybe David (Frei') can shed mor elight on this? If you hit stop before the web browser had completed sending the stream to the server, it would most likely cause an error on the web server as the content-length specified in the header would be different from what it received. However hitting stop once the server has received the complete HTTP message would have no effect. There may be a function in PHP that allows you to check whether the client is still connected (Classic ASP had such a function) and decide whether to continue processing the script based on that. Hitting stop will put the browser into a disconnected state.
|
|