|
|
|
|
![]() ![]() |
Aug 11 2007, 02:08 PM
Post
#11
|
|
|
Super Member Group: [HOSTED] Posts: 500 Joined: 5-November 06 Member No.: 17,016 myCENTs:NEGATIVE[-20.12] |
Asynchronous Processing is actually running the code not synchronous with the activity from the users. It also means running in background with crontab or as what dserban mentioned. It's having your event update scripts in one page, then have something call it every minute. If you can't get crontab, then if your server allows fsockopen, you can call back to your page, and have to run by itself, either indefinitely or, call itself back, with a special limited pattern, so it keep running in the background. Another method is using AJAX, to call the script from the user side from time to time, even though the user is not refreshing the page. For all this, you need some kind of method to keep track of the running thread, so if there's already a thread doing the job, the current one can skip and return right away, to save processing.
Seriously, if you really need to do such a complex game, it's worth to buy a hosting with enough supporting features. If you game is not that complex, as not requiring too much processing, then you can try the event update on every page viewing method i mentioned earlier. It's also good to look into other's works. There's a few opensource online game. Try sourceforge.net |
|
|
|
Aug 11 2007, 02:18 PM
Post
#12
|
|
|
Premium Member Group: [HOSTED] Posts: 286 Joined: 17-June 07 Member No.: 22,702 |
it's worth to buy a hosting with enough supporting features If you can't find a hosting platform for your game, I would recommend - at least in a first stage - running the game on your own PC at home and giving your gaming buddies access to it. The only thing you need to do is open a port or two for direct access from the Internet. The ports you probably need to open are 80 for Apache and 3306 in extreme cases. Even with those ports open, you still have the option of controlling which IP addresses (your gaming buddies' PCs) can connect to your online game, even by using the brain-dead built-in firewall that comes bundled with Windows XP SP2. |
|
|
|
Aug 11 2007, 03:20 PM
Post
#13
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
Remember what I said ... ... emphasis on "invisible" ... The PHP script I was talking about has no way of communicating with any browser, so the idea that it would print something does not make any logical sense. It is a PHP script that does not take any input and as well does not produce any output. It's a script that is supposed to run in the background and update database tables in real time based on what online players happen to be doing as they interact with your system. The browser that is connected to your game system might actually run a combination of JavaScript and AJAX to provide interactivity between the online actions of the player and the ever-changing situation in the database tables, which is being continuously worked on by the background script. Yeah it needs to be invisible and it will just update database/tables in the background. I just need to know how i'd go about setting that up. What pages i need etc. Where i'd need to put the code into update the tables etc. How would i go about getting to start, how i'd get it to do that infinite loop every 500 milliseconds... As soon as i know that i'll be happy [thanks for the help ur giving me btw... most appreciated!] |
|
|
|
Aug 11 2007, 03:45 PM
Post
#14
|
|
|
Premium Member Group: [HOSTED] Posts: 286 Joined: 17-June 07 Member No.: 22,702 |
There is a good hands-on example on the fsockopen official documentation page at:
http://www.php.net/function.fsockopen Look a 10th of the way down at the example code posted by: jbr at ya-right dot com There is a sequence of code that looks like this CODE if ( ( $io = fsockopen( "www.yahoo.com", 80, $errno, $errstr, 5 ) ) !== false ) { $send = "GET / HTTP/1.1\r\n"; $send .= "Host: www.yahoo.com\r\n"; $send .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204\r\n"; $send .= "Referer: http://www.yahoo.com/\r\n"; $send .= "Accept: text/xml,application/xml,application/xhtml+xml,"; $send .= "text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,"; $send .= "image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1\r\n"; $send .= "Accept-Language: en-us, en;q=0.50\r\n"; $send .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n"; $send .= "Connection: Close\r\n\r\n"; fputs ( $io, $send ); ... this is the request part (fputs). But then he goes on to use fgets, which is the response part. That you don't need to do ... in fact it's a bad idea to attempt it. Now instead of $send .= "Host: www.yahoo.com\r\n"; you would obviously have $send .= "Host: link-to-PHP-invisible-housekeeping-script\r\n"; Your PHP invisible housekeeping script either reacts to the actions of the online gamers which are reflected in the database as table entries, or otherwise generates random events based on rules you preset - like a Pacman that keeps popping out of random places at random intervals trying to eat you alive if you're not careful. That you need to program yourself, and you need to define how those two things interact by defining the data model correctly. |
|
|
|
Aug 11 2007, 04:24 PM
Post
#15
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
Ah right ace. Thanks alot. I will give that a go very shortly. Just one last tiny question:
$send .= "Referer: http://www.yahoo.com/\r\n"; I would replace the http://www.yahoo.com with my own website address i assume? |
|
|
|
Aug 11 2007, 05:11 PM
Post
#16
|
|
|
Premium Member Group: [HOSTED] Posts: 286 Joined: 17-June 07 Member No.: 22,702 |
Ummmmmmmm ... no.
Actually you only need something like this: CODE $send = "GET / HTTP/1.1\r\n"; $send .= "Host: http://gameserver/housekeeping.php\r\n"; $send .= "Connection: Close\r\n\r\n"; But after taking a better look at the code I gave you, I realize now that you also need to replace fsockopen( "www.yahoo.com" ... ) with fsockopen( "<IP-address-of-your-game-server>" ... ) |
|
|
|
Aug 12 2007, 09:20 PM
Post
#17
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
Ummmmmmmm ... no. Actually you only need something like this: CODE $send = "GET / HTTP/1.1\r\n"; $send .= "Host: http://gameserver/housekeeping.php\r\n"; $send .= "Connection: Close\r\n\r\n"; But after taking a better look at the code I gave you, I realize now that you also need to replace fsockopen( "www.yahoo.com" ... ) with fsockopen( "<IP-address-of-your-game-server>" ... ) right and i'd need to use the above code when someone logs in? |
|
|
|
Aug 12 2007, 10:33 PM
Post
#18
|
|
|
Premium Member Group: [HOSTED] Posts: 286 Joined: 17-June 07 Member No.: 22,702 |
No.
The idea is that you need to kick-start this house keeping process and have only one instance of it running at any point in time. I can imagine that you would have an administration / superuser section for your game, where you pull all kinds of levers to control the game. The above code would be part of a page in this administration section called "Kick-start housekeeping process". The link to this page would be active if the process is not already running, and would be greyed out or missing altogether if it is. Or something to that effect, it's really up to your imagination, personal preference and talent for designing systems. |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
Lo-Fi Version | Time is now: 20th November 2008 - 05:48 PM |