Page 1 of 1

More files of smaller size vs one big file

Posted: Sat Jul 31, 2004 6:54 am
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?

Re: More files of smaller size vs one big file

Posted: Sat Jul 31, 2004 8:21 am
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.

Posted: Sat Jul 31, 2004 8:22 am
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.

Posted: Sat Jul 31, 2004 8:36 am
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.