I'm building a webapp using php, ajax, javascript, mysql. I've been worring about something for a while, but not sure if it's really a problem or not. Here's the basic concept of how the code is working...I would like to know if I should change it now, or if it is o.k to use as is. Performance is important to me...over 5,000 users should be able to use the app without much of a performance problem. Part of my worrying is just paranoia of being self taught developer and not knowing all the best practices out there.
Here's the basic webapp functionality:
user executes a call via the browser through onclick event --> ajax call to phpPG1.php. --> phpPG1.php runs a query against the db and stores the results in array, then includes another php page called HTMLphp.php, instantiates new object from HTMLphp.php page, which is a class --> calles function of the class and passes the array that contains the results of a query-->the class functions builds the HTML table and passes back a string --> the phpPG1.php page sends back the string with the table data to the ajax call which displays the string in the given DIV tag it belongs in.
The HTMLphp.php contains all the functions that are used to return HTML tables for the whole webapp. HTMLphp.php would look something like this:
Class HTML_stuff
{
function html_TABLE1($results_array)
{
$string = 'THE HTML TABLE WITH ITS DATA IN IT'
return $string
}
function html_TABLE2($results_array)
{
$string = 'THE HTML TABLE WITH ITS DATA IN IT'
return $string
}
}
So, here's my question. the HTMLphp.php page has 5,606 lines of code in it right now, which represents 100 or so functions in the class. Basically, every page in my webapp "includes" this page into it in order to be able to use the class functions to display the html tables. I'm about half way done with the webapp, so there will be a lot more lines of code do add to this file. I'm not exactly up to par on how computers execute code, especially when using class objects, but I understand the basics if "interpretive languages" like php.
I'm wondering if this is a bad idea and if I should do something like this: For each function inside the HTML_stuff class just simply remove the code for each function and place it in it's own separate .php page that gets included like this:
Class HTML_stuff
{
function html_TABLE1($results_array)
{
include_once 'TABLE1.php'; //the html table for this function.
return $string;
}
function html_TABLE2($results_array)
{
include_once 'TABLE2.php';
return $string;
}
}
My basic assumption is that I only include the HTML needed when I make the call to the particular function, thus reducing the overall size of the HTMLphp.php page assuming this would help in overall site performance...am i in left field with this thinking? Part of me is thinking that this is simply the same as the first option, just organized differently and it would do anything to the overall performance. However, I did read somewhere that fewer "includes" is better for performance.
What do other people do, or are there other best practices on how to do this sort of thing? Is it negligible to worry about this with a site of say 5,000 - 10,000 users?
Thanks.