Solved

How does PHP File Size Affect Performance?

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now