Welcome to WebmasterWorld Guest from 184.72.177.182

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How do I safely run a continuously running script?

     
12:42 am on Jan 14, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 5, 2006
posts:69
votes: 0


Let's say this is for a PHP-driven game, run client-side via browser. If I don't want the script to wait for input from players, again, let's say there are entities in the game which will act on their own and I'd like them to do that even when no one is actually playing. How do I pull that off without hogging a server's resources?
1:15 am on Jan 14, 2010 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 14, 2008
posts:2910
votes: 62


I'm not sure, but one thought I'm having is to look at pre-compiling your script and see if that makes it possible for you... One of the problems with constant running is browsers and servers timing out the script execution. (If you're on your own box you have more flexibility here, but otherwise you probably won't be able to have the script run constantly, unless maybe you can somehow do it by pre-compiling.) There's one I run that takes literally a couple of days and I have to set a meta refresh on it for every 40 seconds (using firefox) and then when I hit the max redirects I have to manually reload the page and start it over.

The other thought would be JavaScript and save the state on every change and only update when it's open in at least one browser window. I personally think JS/AJAX is probably going to be your best bet to get close to what you're looking for if you're concerned about resources and/or don't have your own box.

Not sure on other options, maybe someone else has some better ones...

1:28 am on Jan 14, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 5, 2006
posts:69
votes: 0


Yeah, I was thinking AJAX myself. I know a PHP script can be opened and left running, but it seems to me it'd be a lot easier to just use a backend AJAX app on my client and couple that with whomever else is accessing the script... so if the power goes out or something the script will still be running. Maybe.
1:39 am on Jan 14, 2010 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 14, 2008
posts:2910
votes: 62


I know a PHP script can be opened and left running

Until you hit the max execution time of the box your script is hosted on. I've run into it a couple times on one box anyway...

1:56 am on Jan 14, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 27, 2003
posts:732
votes: 0


Have you considered languages other than PHP for this task? PHP doesn't seem particularly well-suited for this sort of thing.
6:10 am on Jan 14, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 5, 2006
posts:69
votes: 0


I have, and I've also considered how stubborn I am. I know PHP/MySQL and DHTML... and every time I attempt to do something with C++ or similar languages I hit a brick wall of libraries and a lack of documentation.
8:30 pm on Jan 15, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 17, 2006
posts: 195
votes: 0


Hi!

Some time ago, I read something about PHP daemons, which can run in the server background and can be a solution for your game...

You can read more about daemon on:
[pear.php.net...]

What kind of information do you want to run automatically?

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members