Search code examples
phpmysqlperformancewampserverforum

What is the ideal target time for rendering a page of a PHP forum?


I am creating this question because I am currently working on my free time (for fun) on a PHP forum, using MySQL for my database. And for a little while now (most of the essential features being implemented), I have been questioning the performance of my scripts.

I already did some profiling of my scripts and improved some of them, but I eventually always end up with the same question: what is a good target time to render the typical page of a forum ? In my case, such a page consists in displaying 20 to 50 messages of a given topic (users can decide how many messages per page they want to display) with roughly half of them using features like uploads displayed as a gallery below a message (which involves string parsing and checking the existence of a file with file_exists()).

After reading some topics on performance with PHP on this website, I learned, among others, that Youtube had a target render time of 100ms (= 0,1s). I managed to have load times below this target time for my heaviest pages, but only after a while due to PHP caching with file_exists() (I run my project locally, with a WAMP Server). But I doubt I can really compare my project to a website as heavy in features as Youtube. So,

  • When rendering (in HTML/CSS) my "typical" page, what time should I target ? Is it acceptable to stick to the 100ms limit, or should I go way below (for example, below 50ms) ? Are there any known statistics about current state-of-the-art forums I could use for reference ?

  • Since I am currently working with WAMP Server, does it introduce bias while profiling my scripts ? Is it equivalent to your average PHP-enabled HTTP server, or does it run slower/faster on average ?

This question interests me a lot, as some features I designed add some overhead to my scripts (which scales with the amount of messages being displayed). For example, my format code to embed videos is not parsed at the creation of a message, but at its display, as I want to be able to easily change the embed code as well as allowing users to choose how videos are embedded (directly, or with small/HQ thumbnail which is replaced with the embed code upon clicking) for their comfort. Of course, I could as well parse the code at the submission of a new message to reduce the overhead, but I want to be sure this is necessary.

I hope this is not too vague... thank you in advance for your answers.


Solution

  • To be honest, I think your interest far exceeds your needs, and there are far too many other factors that come in to play as to the speed PHP executes your scripts. It's something to look at once you've got a baseline reliable server environment set up and consistently running.

    It's pretty meaningless to say to you "Oh but you need to keep your PHP executions below 0.1 second" because so few of the things influence the speed of execution are practically controllable, unless you're actually hands on managing the server (such as setting how many users there are, or adjusting the RAM, or setting what security provisions are in place). You reference in comments you would be on a shared server so one of the biggest influences on the speed the execution runs is the numbers of other users and the size of their PHP applications (as well as the server setup, status, etc. etc.).

    This topic would be something to take up at https://serverfault.com/ possibly. But answers (anywhere) will be generalised opinions and so in my view will be mostly worthless. These are just some people who think that a program taking a few tenths of a second longer than some other program is a terrible thing, it has very little weight on the output end result, being the internet displaying a page on the end point browser, there are a lot of other ways to make that event occur faster and more efficiently....

    PHP execution time is something you will have relatively little control over but it's something that will be almost negligible compared to the HTTP request time, it's far more useful to examine the HTTP request times and doing things like caching static files and minifying CSS/ JS associated files so that the pages load faster on the interwebs Your PHP execution time may be 0.05 seconds but your HTTP request time may be anything up to 3 seconds and so that's the area that micromanagement would improve most, really if you want to micromanage loading times the first thing you do is get off a shared server and get your own dedicated server!

    On a shared server environment most the things causing a slower PHP execution will be well outside of your control, such as RAM availability, other systems running on the server as well as which other users are on the server and what they're running with the same PHP.

    Useful link: http://www.webpagetest.org/

    If you do want to check your code is as efficient and fast as possible then I recommend asking this question on Code Review Stack Exchange Site .

    anyhow, Good luck with it :)

    Also the quoted references to Youtube are fairly worthless as Youtube doesn't even run PHP but uses GO programming language.