Jump to content
MakeWebGames

Performance of including .php files


Mint Berry Crunch

Recommended Posts

I prefer to use include('file.php'); for storing game data (predominantly item stats) in arrays as it is easier to manage than SQL tables. Anybody know if there's a performance difference with using this compared to storing it in SQL?

Would it be a problem having a file with hundreds of assigned variables/arrays included on all your pages?

Link to comment
Share on other sites

It could slow down page execution time, as it could take awhile to set up all the variables, not to mention it limits your ability to add stuff through a staff panel .

Another thing you need to consider is the likes of loading an items array with all your items for a user who is looking at the forums. They don't need the items loaded, therefore slower execution doesn't provide any benefit to them

Link to comment
Share on other sites

It could slow down page execution time, as it could take awhile to set up all the variables, not to mention it limits your ability to add stuff through a staff panel .

Another thing you need to consider is the likes of loading an items array with all your items for a user who is looking at the forums. They don't need the items loaded, therefore slower execution doesn't provide any benefit to them

I would disagree related to execution time. Depending how the include file is set up, it could be faster then fetching from the database and assigning records to variables.

I will agree that it limits the staff panel as they will need access to the file instead of fetching and inserting to a database, There could be work-a-rounds for this as well though.

Link to comment
Share on other sites

[MENTION=64603]Sim[/MENTION] I was thinking that the execution time would be slower because he would basically be creating variables for everything that you would normay have in the database. That's a lot of data and a lot of variables that are going to go unused, whereas if you use a database you only take what you need. In theory I think that could slow it down, in practice I'm not too sure.

You could well be right

Link to comment
Share on other sites

[MENTION=64603]Sim[/MENTION] I was thinking that the execution time would be slower because he would basically be creating variables for everything that you would normay have in the database. That's a lot of data and a lot of variables that are going to go unused, whereas if you use a database you only take what you need. In theory I think that could slow it down, in practice I'm not too sure.

You could well be right

 

I said depending how the file is set up. Several factors to consider.

Database's are files themselves, its just they are in a certain format. When we write a query, it scans the file(database) for what we looking for and returns it.

IF and IF I was using a file to store item stuff which would most likely NEVER happen since I would want Staff to create/modify/delete items, and if it was somehow exploited by a staff member, it would be more damaging then having a database destroyed. The database can fixed, or you could upload a back up. If the file system gets compromised, chances are, your database is to and everything bout your game/site is just screwed.

But IF I was using a file to store item data, it would need some careful planning and prob consist of more then one file depending on how many items would be used. I coded some games where I hard-coded the item into the game. The games only used 1-3 items.

Link to comment
Share on other sites

When you retrieve data from a database, the application opens a socket, the service makes I/O calls to proprietary monolithic files, and returns the data to the interpreter extensions which places it into arrays for your application to consume.

Directly including files, well, includes a file that's stored on the disk, or if you're really into optimizing your environment, in memory with a ram disk.

Files can be thousands or even millions of times faster as there are fewer processes and redundant copies of data, and because inclusion is less taxing on the interpreter - but it comes with the trade-off that you have to plan how and where you'll store and refresh your data while ensuring the cache files are never absent when a user needs them.

I hit a wall with mysql years ago because data wait times were impacting performance - even with caching, optimized indexes, and denormalizing. I implemented file caching for repetitive read-only queries using a cli script that runs in a loop, removing better than 99% of the query execution time from each player's execution cycle, which made the game far more responsive even under the heaviest load.

A few hints from experience:

- files are not for everything, use the database to store, update, and pull real-time values for player actions

- store the data everyone uses in the files, and in a useful format (objects and arrays, not just copies of tables)

- serialize and encode the data to preserve structures and avoid issues with inclusion (decode and unserialize to rehydrate)

- separate your cache files based on how often they're updated (no reason to refresh resource values every few seconds when they're updated once a month)

- where possible, update the cache files using a background process to validate changes and ensure proper formatting

Link to comment
Share on other sites

Interesting discussion here. To clarify I am only using it for game content like item statistics and other non-varying numbers to save myself from writing SQL queries. I haven't thought about the staff issue - I wouldn't expect to change the hard coded data unless I am balancing the game anyway.

I am not familiar with caching. Is this a relatively simple thing to implement?

Thanks

Link to comment
Share on other sites

If you don't anticipate the answers to the questions to change, there's no reason to store them in a database - files will offer a drastic performance improvement.

Caching can be fairly simple to implement if you're enforcing code and data separation within your files already. You just need to write the results of your heavier database queries off to the included file as often as needed to account for changes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...