Installing CSS Tidy For WordPress W3 Total Cache Plugin

In my previous two article where i explain how to install Memcache and HTML Tidy for WordPress W3 Total Cache plugin, i forgotten about CSS tidy as shown below,

CSS Tidy allows the server to minimize your CSS without you doing it yourself. However, this largely depend on whether your web hosting provider had installed it for you. Nonetheless,  it is a great additional for every webmaster to have!

Installing CSS Tidy For WordPress W3 Total Cache Plugin

Installing CSSTidy is quite simple on a centos linux machine. All you have to do is to issue the following command.

yum install -y csstidy.x86_64

If its successfully installed, it would really be that simple. However, if you can't find this option, it will be time to do some work.

Installing CSS Tidy alternative

Since the simple step wasn't there for you, we will have to try something manual. Fire up the below command,

rpm -ivh http://download.fedora.redhat.com/pub/epel/5/x86_64/csstidy-1.4-1.el5.x86_64.rpm

and see whether it went successful. If it does, csstidy is installed. If it doesn't try download it and rpm again.

wget http://download.fedora.redhat.com/pub/epel/5/x86_64/csstidy-1.4-1.el5.x86_64.rpm
rpm -ivh csstidy-1.4-1.el5.x86_64.rpm

If it still doesn't work, you should find it on your yum using the following command.

yum install -y csstidy.x86_64

since the rpm was added into your repo. Hope it works 🙂

Installing HTML Tidy For WordPress W3 Total Cache Plugin

In my previous article where i explain how to install memcache on my centos server to use on WordPress W3 Total Cache plugin. The next thing we will want to have on our W3 total cache plugin would be to optimize our html code. In WordPress W3 total cache plugin, it allows us to do that with Html tidy. Html tidy comes with PHP 5.2 and above. However, not all web hosting will provide you with this. If they do not, simply ask them to install it for you so that you can speed up your website for better seo score!

Installling HTML Tidy on Linux Centos

In order to install this on a centos merchant is pretty simple, all you have to do is issue the following command on your linux machine.

yum install -y php-tidy

if you can't find this, simply issue the following command to search for all tidy component in yum.

yum search tidy

the results shown will be the one you want to yum install it.

Installing HTML Tidy on cPanel Server

Well, in order to install html tidy, you can't simply use the command above as it will not work since cpanel blocks certain repo away. You can go to issue in following command and remove the link "exclude".

vi /etc/yum.conf

removing the exclude link will open up the repo that cpanel do not want you to have. However, this will not work. Like i said, html tidy comes with php 5.2 and above. This means that cPanel has disable this functionality and we all know that cPanel uses easyapache to install and configure our webserver in our linux machine. Hence, you should login to your cpanel account and visit easyapache as shown below,

click on EasyApache and Start customize until you see the button "exhaustive options list" as shown below,

click on it and search for the tidy as shown below,

tick on it and click on rebuild. Wait until its done and you will have the option HTML Tidy on your W3 total cache plugin for either you or your client. Once it is installed, you should head down to the option Minify as shown below

and start configure your html tidy 🙂

 

Installing Memcache For WordPress W3 Total Cache Plugin

Today is a very distracted day. I was busy programming until i lose interest and read up google seo blog. There was this article about google page speed that suddenly makes me feel like speeding up all my website just for some seo benefits. The number one thing i notice about speeding up my website are surrounding caching. Hence, i digged down to my WordPress cache plugin W3 total cache and start exploring him a bit (after 10 months). However i was in a shared environment so the only option other than disk caching would be to install memcache on the server (quite some resources for some speed gain). But it does the trick. My server was using Centos 5.6 with cPanel installed.

Installing Memcache on WordPress Server

Follow the below sequence to get memcache install on your server.

#install require library
yum install libevent libevent-devel
#download the latest memcached. take note i'm downloading version 1.4.6
cd /usr/local/src && wget http://memcached.googlecode.com/files/memcached-1.4.6.tar.gz && tar -xzf memcached-1.4.6.tar.gz && cd memcached-1.4.6
#install it and compile
./configure && make && make install
# make sure memcache starts on boot
touch /etc/init.d/memcached
echo '#!/bin/sh -e' >> /etc/init.d/memcached
echo '/usr/local/bin/memcached -d -m 128 -p 11211 -u nobody -l localhost' >> /etc/init.d/memcached
chmod u+x /etc/init.d/memcached
echo '/etc/init.d/memcached' >> /etc/rc.local
# start memcached
/etc/init.d/memcached
# install memcache
pecl install memcache
# restart apache
/etc/init.d/httpd restart
# test whether we get memcahce
php -r 'phpinfo();' | grep 'memcache'

Upon completing the above steps, you should get yourself the option in W3 total cache plugin to use memcache as an option to use as a cache mechanism.

PHP Fastest way to get image width and height

Well, i am currently updating my WordPress plugin. I faced a problem in the past to retrieve image width to determine whether a particular image is require to resize. The problem here is that checking a particular image height and width is expensive job. In order to not impact the loading time of the site using my plugin, i forfeited the capability of resizing and resize the image regardless of the size. The plugin works fine since the resizing is doing it on the fly. However, problems arise when a smaller image is being resize and this is not a desirable result. Therefore, i would like to see whether there is a solution exist that can easily solve my problem.

Getting Image size using getImageSize()

Obviously, the task here is talking about PHP, we will look at the getImageSize() functionality exist within the naive php function. I personally was using this on the plugin to determine the size of the image. However, i immediately removed this after i notice the impact this functionality has caused on my site.

The reason? Remote image will need to be downloaded into your server and then it will be read locally by php. The pitfall here is the time used to download remotely to your server. If all your image is in your server and not somewhere else like in a CDN, this might not be a problem.

Better solutions

Well, the better solutions to get image quickly is to create your own script to retrieve the first few bytes of the file since the size of the image is located there. Credit goes to James @ zifiniti.com for the script below,

<?php
   function getimagesize($image_url){
    $handle = fopen ($image_url, "rb");
    $contents = ""; 
    if ($handle) {
    do {
        $count += 1;
        $data = fread($handle, 8192);
        if (strlen($data) == 0) {
            break;
       }   
    $contents .= $data;
    } while(true);
    } else { return false; }
    fclose ($handle);

    $im = ImageCreateFromString($contents);
    if (!$im) { return false; }
    $gis[0] = ImageSX($im);
    $gis[1] = ImageSY($im);
    // array member 3 is used below to keep with current getimagesize standards
    $gis[3] = "width={$gis[0]} height={$gis[1]}";
    ImageDestroy($im);
    return $gis;                                                                                                                                                       
   }   
}
?>

Assuming you have a large image file, this can really come in handle and reduce the time needed to load a site. But, its still slow! xD

Setup WordPress Subversion in Mac

Well, it has been sometimes since i updated this blog actually. In fact, it has been terribly long that i updated some of my plugins (2 years to be exact). I've been busy with setting up Yii framework couponic site and modifying the system as much as possible till i lost track of time. Since i get the time to breath today, i might as well update my plugins. However, i've already forgotten how to do it. Moreover, i am currently using a Macbook air which really gives me zero idea how to connect to my wordpress plugin subversion repository. But i managed to do it anyway and just thought of writing it down a quick tutorial.

For anyone who forgotten how to connect to the repo, here is how you do it. Firstly, you will need a subversion client a.k.a svn client. For windows, you have tortisesvn where you can find the tutorial i wrote two years ago. For Mac, i use versionapps (only 30 days trial :(). Download it and start installing. Once, it is installed, fire up your version apps.  You will be asked for the following few items

The username and password would be your wordpress plugin details. For the location url, just visit your WordPress plugin and click on the tab "Admin". Within there, there is a link call "SVN Repo" as shown below,

You should see the link as shown below,

copy it and pass it into the sub repo and you are done.

Now, just checkout your repo and start doing work! xD