Solved

How does PHP File Size Affect Performance?

Posted on 2014-03-06
2
728 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
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 109

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Query return divisible by 3 3 27
Custom Wordpress Loop 22 39
PHP: Best way to scan folders and process files 10 40
Showing multiple maps using PHP and Google Maps 8 20
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

828 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