Jump to content

[SOLVED] Single .php file vs many .php files


Azu

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.