Search code examples
performanceoptimizationlampresponse-time

Fast delivery webpages on shared hosting


I have a website (.org) for a project of mine on LAMP hosted on a shared plan.

It started very small but now I extended this community to other states (in US) and it's growing fast.

I had 30,000 (or so) visits per day (about 4 months ago) and my site was doing fine and today I reached 100,000 visits.

I want to make sure my site will load fast for everyone and since it's not making any money I can't really move it to a private server. (It's volunteer work).

Here's my setup:

- Apache 2
- PHP 5.1.6
- MySQL 5.5

I have 10 pages PER state and on each page people can contribute, write articles, like, share, etc... on few pages I can hit 10,000 per hours during lunch time and the rest of the day it's quiet.

All databases are setup properly (I personally paid a DBA expert to build the code). I am pretty sure the code is also good. Now, I can make page faster if I use memcached but the problem is I can't use it since I am on a shared hosting.

Will the MySQL be able to support that many people, with lots of requests per minutes? or I should create a fund to move to a private server and install all the tools I need to make it fast?

Thanks


Solution

  • To be honest there's not much you can do on shared hosting. There's a reason why they are cheap ... they limit you to do stuff like you want to do.

    Either you move to a VPS that allow memcache (which are cheaper) and you put some google ads OR you keep going on your shared hosting using a pre-generated content system.

    VPS can be very cheap (look for coupons) and you can install what ever you want since you are root.

    for example hostmysite.com with the coupon: 50OffForLife you pay 20$ per month for life ... vs a 5$ shared hosting ...

    If you want to keep the current hosting, then what you can do is this:

    Pages are generated by a process (cronjob or on the fly), everytime someone write a comment or make an update. This process start and fetch all the data on the page and saves it to the web page.

    So let say you have a page with comments, grab the contents (meta, h1, p, etc..) and the comments and save both into the file.

    Example: (using .htaccess - based on your answer you are familiar with this)

    /topic/1/
    

    If the file exists, then simply echo ... if not:

    select * from pages where page_id = 1;
    select * from comments where page_id = 1;
    file_put_contents('/my/public_html/topic/1/index.html', $content);
    

    Or something along these lines.

    Therefore, saving static HTML will be very fast since you don't have to call any DB. It just loads the file once it's generated.