Solved

How does PHP File Size Affect Performance?

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

810 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