Wednesday, August 15, 2007

Web Hosting HOW TO: Save your server AND customer when digg/reddit/slashdot effect hits his/her website

So you're running a web hosting business. You have lots of loyal customers, some of them are with you for the past 8 years. One of your customers gets lucky - a huge burst of traffic hits his website. If you don't do something quickly, your server will go down pretty soon. What's your call? "Suspend website, of course". WRONG! Get this - almost EVERY webmaster dreams of getting to the front page of digg, reddit or slashdot. If you have a reputation of suspending everyone who gets to the frontpage, you are to be avoided. Instead, consider other ways to solve this problem. I will share one method with you, we were successfully using it when I was working in one web hosting company a year back. It's a very simple method and takes only a minute to do.

Your customer's website is dynamic, probably running a heavy script which is why your server can't handle the traffic. You simply need to make it static (not all of the website, just the page which is being hit at the moment).

So here's how you can do this:
  1. Save your customer's dynamic page (which is under heavy load at the moment) as a static .html file
  2. Edit your apache config or customer's .htaccess file. You'll need to turn that dynamic page into static one:
    instead of opening http://CustomersWebsite.com/index.php?page=AwesomeArticle
    it should open http://CustomersWebsite.com/AwesomeArticle_static.html
    So when somebody visits this page, static file will be served instead of dynamic even though you see .php in the URL - no php and no MySQL will be touched.
    We'll use mod_rewrite for that. Here's what you need to put to .htaccess file:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^page=AwesomeArticle(.*)$
    RewriteRule ^index.php$
    AwesomeArticle_static.html
  3. Save it and watch your server going back to life. All your customer's website is dynamic except this page.
You can now e-mail your customer informing of what you've done to save his/her website and congratulating on getting to the front page. You have just saved your server and most importantly - your customer!

Once the traffic gets back to normal, you can remove rewrite rules.

There are other ways to solve this problem - making a mirror, offloading to other server, etc.. It doesn't matter how you choose to solve this problem as long as you don't suspend website in the most important time of it's life.

Note: this is a repost to my previous article "Digg effect took down your website. How to come back online with only a few lines of code.".

 
Digg!


Monday, July 30, 2007

Free services will help you save your time and server resources

Once you get a new server, you probably install: webserver (for example, apache, lighttpd), php, MySQL, DNS (bind), email/pop3 server, traffic statistics tool (webalizer, AWStats). If you're trying to save server resources you don't really need to run DNS, e-mail and traffic stats in your server. Outsource. Use free services. That way you can also save your time - not only you won't have to spend your time installing the software, you also won't need to worry about your email server going down or spend several hours trying to figure out how to stop spam you're receiving. So here's how you can do this.

DNS
Many of domain registrars (for example, GoDaddy) provide their own DNS services for free. Simply point your nameservers to default registrar nameservers and then use their DNS service to add DNS A record with your web server's IP address. You can do it way more faster than installing your own DNS server and after that you won't have to worry about your DNS service going down.

E-mail
You probably have a Gmail account. You can use your domain name for Gmail as well. Try Google Apps. I've been using it for quite a long time and I really enjoy it.
http://www.google.com/a/
Once you sign up and add your domain to your Google Hosted account you will have to point DNS MX records to Google's e-mail servers (instruction on how to do that will be provided right after you add and verify your domain). Once you do that, you can enjoy Gmail interface to manage your e-mail.

Traffic stats
Once again, google comes to the rescue. Google Analytics will provide very detailed traffic statistics. All you need to do is to register and copy/paste the google analytics code to your website's html.
http://www.google.com/analytics/


I hope this will help you to save some time and escape from some problems. If you have any questions or suggestions, don't hesitate and use comment section :-)





Realated posts:
Digg/reddit/slashdot effect took down your website. How to come back online with only a few lines of code.

Tuesday, June 19, 2007

Digg effect took down your website. How to come back online with only a few lines of code.

So you have a really powerful and expensive server but you haven't done any optimizations for your website which is probably a reason why it's down now, after only 30 diggs. Don't worry, there's a quick fix to it and only takes a couple of minutes to do.

Your website is dynamic (probably PHP & MySQL). Each time somebody visits a page, your server has to run a php script which would connect to MySQL database and run some queries. Average PHP script would eat so many resourses that without any optimization, Digg Effect would be fatal. But what if instead of that dynamic page you'd have a static .html file there? No need to hit php, no need to hit MySQL - it would run even faster than a script with a really good optimization and much more faster than your current script (maybe up to 50 times, or up to 100 times - depends on how bad is your script) which simply means more visitors can see your page.

Let's say your URL is: http://MySuperWebsite.com/index.php?page=AwesomeArticle

So here's how we'll do this:
  1. Save your dynamic page (which is under heavy load at the moment) as a static .html file
  2. Edit .htaccess file. You'll need to turn your dynamic page into static:
    instead of opening http://MySuperWebsite.com/index.php?page=AwesomeArticle
    it should open http://MySuperWebsite.com/AwesomeArticle_static.html
    So when somebody visits this page, static file will be served instead of dynamic even though you see .php in the URL - no php and no MySQL will be touched.
    We'll use mod_rewrite for that. Here's what you need to put to your .htaccess file:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^page=AwesomeArticle(.*)$
    RewriteRule ^index.php$
    AwesomeArticle_static.html
  3. Save it and watch your website getting back online. All your website is dynamic except this page. This is just a temporary fix. You can now focus on optimizing your scripts.

 


Put a Poll in your Sig - SigPoll.

Friday, May 11, 2007

Firefox vs Opera flame war expands to a higher (and expensive) level

What happens when some people in the forum tries to prove that one browser is better than other? Yeah - a flame war. But what happens when a simple flame war is not enough? The war expands to a higher level - forum AD system. Expensive conversation continues there.

This story happened in Lithuanian webmaster forum uzdarbis.lt. Ordinary discussion about web browsers developed into ordinary flame war. But one of Opera fans was not happy about visibility of his posts and decided to buy ad space in the same forum. He ordered many text ads supporting Opera. Few examples here:

"Forget firefox with new Opera Browser :-) For free". Ad link goes to opera download page.



"Don't click. Unless you want to make your life easier with Opera"



These two doesn't need translation






And so on. There were just too many ads about Opera. Firefox fans were not happy about it. They responded in buying ads bashing Opera like "Opera? Fat ladies singing? Get Firefox.", however I can't find that ad now (there are just too many ads in the rotator at the moment). Few more examples:

"Scientists proved: Firefox is good for you. Opera was created by green aliens as a tool to rule the world."


"Opera experience - as bad as eating snot. Use Firefox."


"Real men use Firefox". Simple as that.



Flame war goes on, flooding the ad system. Seems like some Opera/Firefox fans like their browsers and hate other browsers so much that they don't mind spending money just to show their dedication. What's next?