

Depending on the PHP version it can happen It could already result in 10MB+ memory usage there).ī.) Be sure to eliminate unused variables or variables you need to reinitialise.Įspecially if you use loops. Select all 300k rows (if you have quite a few coloumns with 5-100 bytes each

Thus if only 1 of the 300k rows is really applicable load only that one and dont I'll go into a bit more details to these two things below (also how you could counter those):Ī.) For getting data from the database be sure to only load the really relevant ones. Loading too much data, or having a memory leak in a loop. There areĢ things that I can see where it COULD come from (without knowing the code):
Browser game script download code#
Lines of code sounds like a memory leak is happening inside your code. Another possibility would be memory leaksĮspecially as the phenomenon that you write about with the medium sized data and 1k You can use the MySQL EXPLAIN feature to find out if/when/how an index is used and what generally happens during the execution of a certain query.Īs the others already mentioned.300k of rows from a database and 1k lines of code shouldn't really be that huge of a problem for the memory.Īlthough if you load all 300k rows into memory at once (depending on how much data is in each row) that COULD pose a problem. This will require you to add an ORDER BY clause which in turn might benefit from having a indexed column to sort by, something (but not necessarily) like the primary key. So instead of a language change I'd suggest you use LIMIT/OFFSET features of MySQL to limit the amount of memory that is used by the results at any time, disable some extensions that you don't use and do some throttling (storing server load info and reacting appropriately to high load situations).īy limiting memory usage with LIMIT/OFFSET I meant loading the first N results and checking if result count is N and if so, loading the next N results and repeating this until all results are processed. But it's ~10x faster than PHP.īut never mind what I said about speed because your bottleneck will most probably be MySQL and the data you retrieve and you'll want to keep things simple. Python has a rather uncomfortable reference system so copying data is painful. I think I'd bite that bullet if it's the best option for a better game, though.īetter? Probably, but at what cost? PHP has a truly fully-featured string API which will come in handy as soon as you do just about anything with text.Ĭ# has native code and some added speed at the cost of having to use an awful API and the JIT compilation on first launch makes testing painful. I'd consider non PHP alternatives but, if PHP is suitable, I'd rather stick to that, so there's no overhead of learning something new. but a) am I right to be using PHP at all, and b) am I missing some clever way of doing things that will somehow reduce server resource requirements? I taught myself a modicum of PHP a while ago, and most of the stuff I read online (ages ago) about similar games was all PHP-based. Is there a better way to do something this massive than simply having some functions in a PHP file calling the MySQL Database? The PHP script for the fight logic currently has about a thousand lines of code in it, and I'd say it's about half-finished as I try to add a bit of AI into the fight script. There are about three hundred thousand combinations of combat stance, attack, move and defensive stances, so obviously this is quite a resource hungry process, and, on the super cheapo hosted server I'm using for development, it rapidly runs out of memory.

It's basically one of those MMOs where you level up various buildings and what have you, but, you then commit some abstract fighting entity that the game gives you, to an automated battle with another player (producing a textual, but hopefully amusing and varied combat report).īasically, as soon as two players agree to fight, PHP functions on the "fight.php" page run queries against a huge MySQL database, looking up all sorts of complicated fight moves and outcomes. I'm developing a browser game, using PHP, but I'm unsure if the way I'm going about doing it is to be encouraged anymore.
