KP Solutions

Solutions for Day to Day Technical Problems

April 26, 2012
by Ketan Patel

Commands To Check Server Performance and Stats

The command I normally have been using to check the server performance is the good-old ‘top’ command. Gives you a very good snapshot of the things going on in your server.

However, today when I issued the top command I found that the CPU load was around 16.23 but none of the processes were consuming as much of the CPU. Moreover, all the CPUs showed that they were 0% idle. This is strange, idle time is 0%, CPU average load is 16.23 whereas none of the processes were really consuming as much of the CPU. So where’s the problem and who’s causing it?

While I was searching on several forums for help, I found a nice blog post here and here that gives you a list of very good commands to check a variety of stats. You can read up full details in there, however, I would just list those commands in here for future reference. The commands of interest were:

  • mpstat
  • sar
  • ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
  • iostat
  • vmstat

If you understand the purpose of each of the above command, then it would give you a very good understanding of what your server is undergoing at that very precise moment.

Oh and another command very useful was ‘watch -n1’. If you add ‘watch -n1’ to any of the above listed commands then you would be able to monitor the update to the output of those commands as ‘watch’ runs the command at specified time delay of 1 second.

By the way, at the end of doing the above exercise, I wasn’t able to find the processes or the reason why the CPU load was 16.23 average while each of the CPU was 0% idle. The server was responding fine with the requests and hence I left it alone. Didn’t find the root cause of the problem. I think that some how one of the variables on which top depends was some how messed up. Also, I was pretty sure that this problem will go away once I reboot the server, but I don’t want to reboot server without really having a need to.

Hope, this post would give you some insight in finding more details on performance and stats for your server. If it does or even if it doesn’t, please leave a comment below 🙂

September 14, 2011
by Ketan Patel

Find Sizes of SubDirectories In One Command

Today, I was running out of disk space on my laptop; not quite unusual to happen. However, with this situation of out of disk, I had to get rid of the directories or files which are using most space and I no longer need.

Now, I can easily find the size of folder by issuing ‘du -skh <folder_name>’. But this gets tedious if you have 50 folders in one directory. I didn’t want to run same command fifty times. So, I had two options :

  1. Write a script
  2. Or find a command to take care of this situation
A one line command is way better than script any time for me. So, I cooked up an easy to use command:
find * -maxdepth 1 -exec du -skh {} \;

This one line command gave me the size and filename/foldername besides it. Exactly what I wanted. Hope this helps you!


July 11, 2011
by Ketan Patel

SQL Error: 2006: MySQL server has gone away

So you got an error “SQL Error: 2006: MySQL server has gone away”. Like me if you were wondering where the heck did MySql go away. It was there when the script started.

Ok, I am gonna tell you that there’s a variable in your mysql configuration that is causing the MySql connection to timeout waiting idle. This could happen in the case, when you start the php script, make a mysql connection and then the script is doing some heavy processing, while the mysql connection made initially is sitting idle doing nothing. So in such cases, the MySql will check for the ‘wait_timeout’ variable setting and if the php script didn’t use the mysql connection for the ‘wait_timeout’ interval, the MySql will kill that connection and hence your script will get the ‘MySQL server has gone away’ error.

Solution to resolve this issue, two folds:

  1. If you make the MySQL connection, then you better use it. If you don’t want it then the resource needs to be released so others can use it.
  2. Else If you think that you need the connection and it is OK for it to sit idle for that time, then increase the value of ‘wait_timeout’ during runtime at the beginning of the script by issuing the SQL query ‘SET GLOBAL wait_timeout=60‘ in case you want to set it to 60 seconds and then restore it before you exit your script.

But, as always, if you increase the ‘wait_timeout’ value, check your server performance for another few days and see if there is any negative impact. If no impact then you are OK, but if there is then I would recommend Option 1.

Hope to help,


May 5, 2011
by Ketan Patel

MySql Error#1005 – Can’t create table (errno: 121)

I have been MySql Workbench for a long time now and I recommend everyone to use it for their database design needs. Today, I was exporting the mysql database design to .sql file and then importing the sql to mysql server. I got the error

"#1005 - Can't create table 'XXX.xxxx' (errno: 121)". .

I scratched my head, hmmm…. Error #1005 is for foreign key constraint errors, checked the keys, column type and everything looked OK.

After about 10 minutes of fiddling around, I found that I had forgotten to make the foreign key constraint names unique for that particular table. If you are using InnoDB engine, then you need to make sure that all the foreign key constraint names are unique across the entire database and not just the table.

Hopefully, you may find my post helpful and save you some minutes or hours sometimes.


December 25, 2010
by Ketan Patel

Problem to Share Windows Media Center with PS3

If you, like me, want to share the media from your PC/Laptop with PS3 and were unsuccessful then this blog post will help you out.

Its quite simple and you don’t need to install any 3rd party software to do so. This post assumes you have Windows OS and the PC & PS3 are on same private network. It’s only 2 step process:

  1. On the PC with the media content, you will have to add all the folders with media to the Media Library.
  2. After you have added, then open up ‘Windows Media Player’ and you have to enable Automatically allow all devices and computers to have access to your media.

Once you have successfully followed the two steps above, visit your PS3 and make sure you have ‘Media Server Connection’ checked in ‘Settings’. After that, you should be able to see your PC-name and browse the media library.

As always, if this post helped you solve the problem, please leave a comment or donate if you will to keep me motivated.


December 23, 2010
by Ketan Patel

OSTicket Setup Postfix Email Piping

Yesterday, I got a new server and was setting up a Ticketing server using OSTicket for one my sites. The installation of OSTicket went smooth per the documentation. However, the tricky part was to pipe the emails to osticket so that tickets get created and appended automatically without manual intervention. I searched on net and the information was terse and sparse at the best.

With bits and pieces here and there, many trials and errors and frustation, I finally figured out an easy way to do this. If you using CentOS (it may work on other flavors, but didn’t try it personally, so can’t vouch for it), then :

Say if you want to pipe the emails from ‘’ to ‘OS Ticket’, then edit ‘/etc/aliases’ and add the following line to bottom of the page:

support.domain: postmaster,”|/usr/bin/php -q /home/domain/public_html/api/pipe.php”

This will make sure that the email will be piped to the pipe.php of OSTicket and will create a new ticket or append a ticket depending on the email.

Just one line to do the email piping for Postfix mail server, but took me a day to get here! Hope you get to this post on first search!

Please feel free to leave the comments and join the discussion.



December 18, 2010
by Ketan Patel

PS3 Internet Connection Issues 80130182

I bought a PS3 and boy, I love it no doubt. However, I was having problem with my PS3 Internet Connection. I was using Wifi on PS3 to connect to the internet. The PS3 would connect to internet and then drop the connection intermittently, even though the wifi signal was 100%. WIFI would work fine on other laptops and PCs in network, just PS3 had issues.

I was annoyed with this and reluctantly decided to return the PS3. But then thought, let me call the support, so I called PS3 support centre and the guy suggested several things. Of that he suggested to turn off the WEP encryption on the WIFI network. Once I disabled the WEP encryption, the internet connection on PS3 was rock-solid. No drop in connection any longer. But this can’t be a permanent solution I mentioned to support guy. He said that its not a problem with PS3, its something with your router. I wasn’t satisfied with that answer, but still thanked him as I got the internet working on PS3.

After that I reset my router to use WEP 64 bit encryption. I set up the PS3 to use the WIFI again but this time using the 64-bit WEP encryption. Eureka… it worked. No issues. Then I set the router to use WEP 128-bit encryption. The problem came back on PS3. So conclusion of the story, use WEP 64-bit encryption on your router and PS3 to avoid the 80130182 issue.

Hope that helped you…

August 23, 2010
by Ketan Patel

Unable to load dynamic library php_mysql.dll

While trying to setup Apache, PHP and MySql on your development machine or server, you may face several hurdles and one of them would be unable to load the mysql library. On my windows development machine, I got a problem while trying to load mysql library. I got following error:

PHP Warning:  PHP Startup: Unable to load dynamic library ‘./php_mysql.dll’ – The specified module could not be found.\r\n in Unknown on line 0

The problem is two fold here:

  1. The extension directory path is incorrect
  2. And php module isn’t able to find libmysql.dll

To resolve the issue:

  1. Update ‘extension_dir’ from ‘./’ to ‘G:/Server/php/ext/’
  2. Update the ‘PATH’ variable on your computer to include the PHP directory (G:\Server\php) in my case.

Hope this will save you time and trouble of finding a proper solution.

July 8, 2010
by Ketan Patel

How to limit connections per User IP in Apache 2.2 CentOs

If you are a system admin or a webmaster, you will face this question at some point of time. How do I limit connections per user ip in Apache 2.2? Generally, you get good users visiting your site who use the site normally requesting one or two page at a time. But then there are a few malicious user who would want cause grief to you and your server by overloading the server with requests. To handle such malicious user, you need the mod_limitipconn module. This module keeps check on the number of connections a single ip can make simultaneously. There are configurable options that help you tune this module. So, now to the point.. How do I install this on my server?

I am outlining the steps for my server, ie. CentOs 5.2 with Apache 2.2

  • wget
  • rpm -i mod_limitipconn-0.23-4.el5.x86_64.rpm
  • vi /etc/http/modules/ipconn.conf

    Add following to the content of ipconn.conf
    # LimitIPConn module limits the number of connection to apache
    # per IP address. This helps in limiting the simultaneous downloads and will help
    # prevent slow users from blocking your servers.
    <IfModule prefork.c>
    LoadModule limitipconn_module modules/

  • Make sure ‘ExtendedStatus‘ is ON in /etc/httpd/conf/httpd.conf
  • You will have to configure the module for each of your virtual host that you need to implement the limitip for.

    <IfModule mod_limitipconn.c>
    <Location /forums>
    MaxConnPerIP 3
    # exempting images from the connection limit is often a good
    # idea if your web page has lots of inline images, since these
    # pages often generate a flurry of concurrent image requests
    NoIPLimit image/*
    <Location /video>
    MaxConnPerIP 1
    # In this case, all MIME types other than audio/mpeg and video*
    # are exempt from the limit check
    OnlyIPLimit audio/mpeg video

  • Save the config file and test the new configuration “/etc/init.d/httpd configtest”. If you get “Syntax OK”, then all you need to do is restart the server and you are good to go.

This is a brief guide on how I got mod_limitipconn working on my server. If you have any questions, please feel free to post in comment and I will try to answer your questions.

February 9, 2010
by Ketan Patel

Error encountered while installing Microsoft Office

If you encounter an error while installing Microsoft Office, then you need to do the following steps to resolve it. From an administrator account, do the following:

  1. start -> run -> Type “msconfig” -> click on ok
  2. Check the box selective startup
  3. Under selective start up uncheck the 1,2 and the 4 options
  4. Click on the services tab
  5. Check hide all microsoft services
  6. Click on disable all
  7. Click on apply and ok
  8. When asked, restart the computer
  9. Wait for restart to complete and then log on to administrator account
  10. Start -> Run -> Type “msiexec.exe /unregister” ->  click on ok
  11. Start -> run -> Type “msiexec.exe /regserver” -> click on ok
  12. Now insert the disc and install the office software

Hope this helps you in case if you encountered an error while installing Microsoft office.