Solved

How does PHP File Size Affect Performance?

Posted on 2014-03-06
2
752 Views
Last Modified: 2014-04-09
Simple Question: Is it better to split code between a bunch of smaller files or put it all in one big file.

Background:
I have a Website application that has about 50,000 lines of code to run the whole thing (event registration in a shopping cart format).

This is an ongoing project so most of the deployment files are not compressed and they have a lot of comments and notations. So at this time yet there still is a lot of code bloat.

I have around 100 different functions that I've written to perform various tasks.  I am wondering what option is best for bringing the best performance. There are four main tasks: 1) Login and Authentication; 2) Registration; 3) Housing; 4) Payment.  Each of these tasks is handled by a parent php files (e.g. auth.php, reg.php, house.php, pay.php) that calls in a bunch of other files as needed (load.php, navbars.php, etc.)

There are about 30 of the 100 functions that are used by all four, but then the remaining 70 are used by only one of the processes.  

Restated Question:
Will my site perform better if I put all 100 functions in one big file (of 25,000 lines) or split them up based on use? Will the one big file get cached and perform better or will it work better to split it all up. So which of these options?  

1) Put all 100 functions in one big file.
2) Put the 30 common functions in one file and then split the others into separate files based on the parent script that calls them.
3) Put the functions at the front of the parent file and make the parent file bigger.

What I'm looking for here is advice regarding performance.

Thanks.
0
Comment
Question by:pkonstan1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 75 total points
ID: 39909379
Splitting code will involve a disk loopup for the file which will obviously take more time albeit millisecs.
But best practise is to separate common code into includes and separate logic as much as possible from the HTML (e.g. functions) - I assume you are not using any kind of framework.

The best thing you could do is install an accelerator like APC which will compile and cache the pages in memory.
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 150 total points
ID: 39909961
Regarding performance, the best thing is to have all of the scripts and data in one file and load that one file.  You can prove this to yourself by setting up a test with something like Composer or by using the auto-loader for your classes.

The reason for this is that disk I/O operations have an overhead factor to them.  You have to find the file(s) and this process takes several read operations.  Then, once found, you can read the file.  If you have many files you incur many instances of the overhead.  If you have one file, you only incur one instance of the overhead.  

If you separate the CSS and JS, the client browser may cache these, and that may save you some load time after the initial capture.

An object lesson in this can be found in many WordPress sites, where extensive CSS and JavaScript collections are piled up.  Some of those sites take multiple seconds to load.  You wonder what they were thinking!  A way to look at performance is to get YSlow or something like it for Chrome and see what it tells you about page load time.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php hashing methods 3 49
How do I allow for non standard CSV file 9 45
Code not executing correctly. 3 43
SSL unsecure page mystery 17 46
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question