Azu Posted February 5, 2007 Share Posted February 5, 2007 Is there any performance difference between using 1 giant .php file and using a bunch of little .php files? Besides that I have to upload the whole giant file every time I update something? I thought there would be a simple answer to this but google has failed me :-\ http://www.google.com/search?hl=en&q=Giant%20php%20file%20vs%20small%20php%20files&btnG=Search+Images&ie=UTF-8&oe=UTF-8&sa=N&tab=iw Oh and if there is a difference, what is it? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 Personally, i like to have smaller php files that link to each other, like i have header.php, footer.php, menu.php. in this way, when i edit one php file, all the other pages get updated, and this saves both space and time when designing your pages. but thats my opinion. Ted Quote Link to comment Share on other sites More sharing options...
tarun Posted February 5, 2007 Share Posted February 5, 2007 Personally, i like to have smaller php files that link to each other, like i have header.php, footer.php, menu.php. in this way, when i edit one php file, all the other pages get updated, and this saves both space and time when designing your pages. but thats my opinion. Ted I Agree This Is A Much Easier Way Of Editing Content Like Navigation Menus Quote Link to comment Share on other sites More sharing options...
Azu Posted February 5, 2007 Author Share Posted February 5, 2007 Personally, i like to have smaller php files that link to each other, like i have header.php, footer.php, menu.php. in this way, when i edit one php file, all the other pages get updated, and this saves both space and time when designing your pages. but thats my opinion. Ted This is what I do with 1 big file, only with functions instead of includes. Is there any performance difference? I'm not really sure how to benchmark something like this myself.. microtime definitely isn't accurate enough Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 yeah, you can have a big file that has all of your functions in it, and require it on every page, since redefining the functions on each individual page costs a lot of memory and effort. but i dont understand about the microtime thing, sorry. Ted Quote Link to comment Share on other sites More sharing options...
Azu Posted February 5, 2007 Author Share Posted February 5, 2007 yeah, you can have a big file that has all of your functions in it, and require it on every page What?????? I think I worded my question wrong. I meant to ask which is faster, 1 big file with functions in it, or a bunch of little files using includes. I didn't mean 1 big files AND a bunch of little files. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 small files are definitly more faster than bigger files, but when talking about the webmaster's convenience, id prefer bigger files having all the functions in it. Quote Link to comment Share on other sites More sharing options...
Xinil Posted February 5, 2007 Share Posted February 5, 2007 The difference between one huge file and one file with many includes isn't in execution time or performance, but rather security and usability. One huge file is very easy on security. If you're checking sessions, simply check the session in whatever part of the file you want. However, if you're using multiple files, you have to check session data on the included file. This is necessary because what if some user somehow finds that included file on your server? Now they can access it in a way that it wasn't originally intended (i.e. they go to menu.php instead of index.php). Authentication control is necessary on an include setup (each and every page needs it). Another issue with giant files is upload time. If you're uploading a 150Kb file and someone is trying to view the page while you're uploading it, they'll get an error. Smaller pages with includes fix this error. Smaller pages with includes also prevent bugging errors from crashing your whole site. If you include a file that has an error on it, only that page will error when called, not the whole site. So, it's really a give and take. includes = some security risk, but greater flexibility overall. Having a massive "functions.php" is perfectly normal. I don't know why anyone wouldn't have one of those. I'm referring to a whole website setup tough. Quote Link to comment Share on other sites More sharing options...
Azu Posted February 5, 2007 Author Share Posted February 5, 2007 Okay, thanks for the detailed explanation. I think I understand it better now. 1 last question though Is it possible to make it so that a file can be accessed, but only by includes? So that I can have some file somewhere, and it will work if I include it, but it can't be accessed directly? This would be really useful for preventing people from directly accessing files, so that I could just only include it if they are logged in for example, so if they aren't they would have no way of accessing it Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 use .htaccess: <files "*.*"> deny from all </files> Ted Quote Link to comment Share on other sites More sharing options...
craygo Posted February 5, 2007 Share Posted February 5, 2007 You can also put it outsite your webroot directory. Being somewhere outside the webroot, you can only include the file but will not be able to browse to it. I think ted's suggestion may be a better way though. Ray Quote Link to comment Share on other sites More sharing options...
Azu Posted February 5, 2007 Author Share Posted February 5, 2007 Thanks everyone I think I'm going to use BOTH of those methods, just to be on the safe side Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.