Page 1 of 1
MVC, file_get_contents, and speed
Posted: Thu Aug 02, 2007 8:22 pm
by superdezign
So I'm extremely proud of myself as of right now, as I feel I have finally programmed a website in an actual MVC format. When I put PHP into HTML, I didn't like it. Then, I tried putting HTML into PHP, but it was still too cluttered. Now, I've separated form from function completely (aside from a form handling class that I made which handles it's own display) and it feels a LOT neater and much more organized and object-oriented.
The only problem is that there's an extra overhead of loading my templates. I use file_get_contents() and offline, the speed decrease is not noticeable, but online it most certainly is. I'm curious if anyone is aware of some methods I could implement to decrease the overhead. I've considered cache control, but on pages that require no-cache, I'd still need to call file_get_contents (and they tend to be the most content-heavy pages).
Posted: Thu Aug 02, 2007 8:43 pm
by Benjamin
This is [s]the reason[/s] one of the reasons why I rolled my own framework.
Posted: Thu Aug 02, 2007 8:57 pm
by superdezign
astions wrote:I rolled my own framework.
Say wha...?
Posted: Thu Aug 02, 2007 9:18 pm
by Benjamin
I built my own, from scratch. The site om-pass.com runs on last years version. It's very, very quick. I'll probably be releasing it within the next year or so. I think I have about 140 hours left or so to complete it. Just need to find the time.
Posted: Thu Aug 02, 2007 9:24 pm
by superdezign
Yes, I've built my framework but am curious as to a good way to optimize my template parsing. How do you do it?
Posted: Thu Aug 02, 2007 9:33 pm
by Benjamin
Well I have a lot of tricks up my sleeve and really approached it from a different angle than most programmers would. I would guess that most of the difference in rendering speed that your seeing is not related to the speed of the PHP code, but rather the latency of the connection. You could always test that by throwing a chronometer on the pages to verify that.
If I'm wrong, and that isn't the issue, or your just trying to squeeze every ounce of speed you can out of the code, I think the next step would be start caching pages. You can't really increase the speed of file_get_contents.
There are also other things to look at. Are you on shared hosting on a server under high load? What type of internet connection do you have and what is the ping time to your server? Is your remote server compressing the pages, adding to the time it takes to render in your browser? Are you running preg_replace a lot and doing a lot of string processing? Is the framework? Is it including tons of files you don't need? Loading tons of classes? Is the page using tables? etc.. etc..
There's a bunch of stuff that could cause that. Nevertheless I think that most frameworks are similar to aolware in that they are bloated. I prefer not to use them.
Posted: Thu Aug 02, 2007 9:44 pm
by Christopher
I don't see how loading two files rather than one has caused such a speed decrease. And I really don't understand "offline, the speed decrease is not noticeable, but online it most certainly is"? What does "offline" and "online" mean? I am guessing localhost vs a server somewhere?
Posted: Thu Aug 02, 2007 10:12 pm
by superdezign
astions wrote:There are also other things to look at. Are you on shared hosting on a server under high load? What type of internet connection do you have and what is the ping time to your server? Is your remote server compressing the pages, adding to the time it takes to render in your browser? Are you running preg_replace a lot and doing a lot of string processing? Is the framework? Is it including tons of files you don't need? Loading tons of classes? Is the page using tables? etc.. etc..
Right, I *am* on a 56k connection, and the page doesn't load slowly, but there is a pause between clicks and anything new being displayed to the browser. I was quick to blame that on file_get_contents(), but then I started thinking about it and all of my operations are performed before anything is displayed to the screen, And then after all of the processing, it is echoed. So, on second thought, I guess there is no real problem.
arborint wrote:I don't see how loading two files rather than one has caused such a speed decrease. And I really don't understand "offline, the speed decrease is not noticeable, but online it most certainly is"? What does "offline" and "online" mean? I am guessing localhost vs a server somewhere?
Yeah. Basically, on localhost, it's instant, but on the server, there's about 5 seconds from one page load to another (after images are cached) on my 56k. I'm so used to DevNetwork loading in like 2 seconds, 5 seconds seemed like a long time, but after browsing more websites, it's actually very fast. I guess I was just begging for some sort of deficiency for me to fix.

Reply
Posted: Fri Aug 03, 2007 3:28 am
by user___
Hi guys,
I have a similar framework and I think that it works pretty fine. I use a standart way of obtaining values. I have a class which parses html and .html template files. What I do is when a request to a page is sent my class checks the passed values and get the source of the page in which there are dynamic vars which are replaced with their values from a database. If your site is slow then use PEAR package and check every page's loading time. Then you can create a script which simulates a real situation. You should define a number of users(for example seventy or any number you want) and test your script on your localhost. You should do that with a smaller number than the number you expect to have on your server because I suppose that your own computer is not a server. If your server behaves good during the test then you have no problems with your Php and can keep using that class else you should fix it.
BTW:It is a tendency for many people not to pay the needed attention on some very small bugs in their code and that's why there are so many slow scripts on the Internet.
For example a bad programmer would write:
Code: Select all
for($i =0 ; $i< count($users_arr); $i++) {
}
While the good one would write:
Code: Select all
$num = count($users_arr);
for($i = 0; $i < $num; $i++) {
}
I know that this is pretty basic code but it is a common way of creating a loop.
Re: Reply
Posted: Fri Aug 03, 2007 8:02 am
by superdezign
That is very good advice. As I was writing this website, it started out sloppy and became neater as time went by, since I don't really plan my structure ahead of time... I just make it. Now that I have the majority of the classes produced, I've been re-factoring the entire website and have noticed a few deficiencies here and there. Most of these were MySQL-related, where I'd either break something into two queries where one would suffice, or I'd do too much in one query where two would be faster.
I hadn't really considered clocking everything (other than my search queries)... That could prove very useful.
Posted: Fri Aug 03, 2007 3:47 pm
by Christopher
astions wrote:Well I have a lot of tricks up my sleeve and really approached it from a different angle than most programmers would.
Care to share some insights?
Posted: Fri Aug 03, 2007 6:27 pm
by Benjamin
Not yet, but I will.