homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

How do I safely run a continuously running script?
Clinton Labombard

 12:42 am on Jan 14, 2010 (gmt 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)

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...

Clinton Labombard

 1:28 am on Jan 14, 2010 (gmt 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)

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)

Have you considered languages other than PHP for this task? PHP doesn't seem particularly well-suited for this sort of thing.

Clinton Labombard

 6:10 am on Jan 14, 2010 (gmt 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)


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:

What kind of information do you want to run automatically?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved