Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How does PHP File Size Affect Performance?

Posted on 2014-03-06
2
Medium Priority
?
855 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 300 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 600 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 dynamically set the form action using jQuery.
Suggested Courses

963 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