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?
More files of smaller size vs one big file
Moderator: General Moderators
-
DarkUnderlord
- Forum Newbie
- Posts: 2
- Joined: Sat Jul 31, 2004 6:54 am
Re: More files of smaller size vs one big file
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: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?
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);
?>If you organize your file structure properly, it is not difficult to have a "clean file system" even with hundreds of files.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.
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.
At http://www.tonymarston.net/php-mysql/index.html you'll find some relevant articles on php-mysql too.