More files of smaller size vs one big file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DarkUnderlord
Forum Newbie
Posts: 2
Joined: Sat Jul 31, 2004 6:54 am

More files of smaller size vs one big file

Post by DarkUnderlord »

Hi, first post (hoping I got the right forum too - though I figure this is more a design / theory question so...).

I'm working on a web-site with a PHP / MySQL back-end and part of what I'm doing is creating scripts that, oddly enough, enter data into a database. News items, game details and the like. So a user who logs in as an administrator can fire up the games.php file, follow a link and add a new game to the database with it and so on.

Anyway, my question is: Taking games.php as an example. I currently use the same file to add, edit, delete and view data from the database. All depending on a '?mode=' in the URL (though if no mode is set, 'view' is default). As a result, I have a file that weighs about 30 kb...

Thing is, most of that 'weight' is error checking stuff for adding and editing data. Does this slow down performance? Given that the majority of people who go to the file will be viewing data only, should I break that part out into its own file and keep the add / edit / delete stuff in a seperate file elsewhere?

While having one file is neat (it keeps all the code related to games in one spot) I presume that for the server to process the larger file takes more time than it does to process a smaller file? What other advantages / disadvantages are there?

Taking this further... would it be better to have 4 different files with add, edit, delete and view data modes all having their own file? Then, as the code used to 'view' data is also the same code used in add / edit and delete modes for previewing the data to the administrator, would it be best for this 'common info' to be broken off into yet another file which is included in these other files?

My thinking when I first designed this "one file for all modes" was that having one file that did everything related to that task would mean I keep a cleaner file system. I wouldn't lost files in places and it would be an easy system. Need to modify the games system? Get games.php. Rather than "find all files associated with this system and hope you get them all". Does anyone have any design tips for keeping track of files that are related to the same database system?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Re: More files of smaller size vs one big file

Post by hawleyjr »

DarkUnderlord wrote:file that weighs about 30 kb... Thing is, most of that 'weight' is error checking stuff for adding and editing data. Does this slow down performance?
30 kb isn’t too large; however, if each individual's mode's error checking is rather large then store the error checking in an include file. PHP will only load the file if needed. See below:

Code: Select all

<?php
switch (mode){
case 1:
$r='/errorfiles/errorchecking_mode1.inc.php';
break;
case 2:
$r='/errorfiles/errorchecking_mode2.inc.php';
break;
default:
$r='/errorfiles/errorchecking_mode1.inc.php';
break;
}
include($r);
?>
DarkUnderlord wrote: having one file that did everything related to that task would mean I keep a cleaner file system. I wouldn't lost files in places and it would be an easy system.
If you organize your file structure properly, it is not difficult to have a "clean file system" even with hundreds of files.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Another thing, post some code. I'm willing to bet this good weather that the majority of it can be cleaned up and put in functions to reduce redundancy.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You may want to read http://www.marston-home.demon.co.uk/Ton ... small.html

At http://www.tonymarston.net/php-mysql/index.html you'll find some relevant articles on php-mysql too.
Post Reply