Home > Wordpress Plugins > Distributed Media; a WordPress Challege

Distributed Media; a WordPress Challege

April 27th, 2009 Leave a comment Go to comments

Though when the team at Saturn decided to build kerala online, on wordpress, they were quite confident, the complications started to get under their skins when the first wave hit the portal and at a point were the portal was being run from a single server and reached about 35K visits per day. The server was running on apache with about 2G Memory and hosted in Asianet the ISP division. There was times when the server was running at load averages above 60. All workarounds were getting futile, and there was certain times, like evening and early morning when the server hits the upper limit and ceases to respond. The easiest solution suggested by a brainstorming session was to distribute the media. Since the same server was serving streaming videos, and content related images, which we could easily synchronize to a different server and using an appropriate plugin, we could link out the contents. The plugin which we used is

<?php
/*
Plugin Name: WP-KOL-Media
Plugin URI: http://www.saturn.in
Description: Replaces all media files from '/wp-content/uploads/' to respective mirror servers as url.
Version: 1.0
Author: Jiju Thomas Mathew
Author URI: http://www.php-trivandrum.org
Author Email: jijutm@saturn.in
*/
 
function jtm_wpKolMedia()
{
  function 
exactRewriteUrl(&$v$key){
    
$trg 'http://images.keralaonline.com';
    if(
eregi(".flv$"$v))
       
$trg 'http://videos.keralaonline.com';
    if(!
eregi("\.php$"$v))
      
$v str_replace('http://keralaonline.com'$trg$v);
  }
 
  function 
doMediaUrlRewrite($buffer)
   {
      
preg_match_all("#" get_bloginfo('url') . "/wp-content/(uploads|themes)/(.+)#i"$buffer$m);
      
$new $m[0];
      
array_walk($new'exactRewriteUrl');
      return 
str_replace($m[0], $new$buffer);
   }
 
ob_start("doMediaUrlRewrite");
}
 
add_action('get_header''jtm_wpKolMedia'999);
?>

Categories: Wordpress Plugins Tags:
  1. No comments yet.
  1. No trackbacks yet.

fifteen − = nine