Disk usage check via PHP

Just a few days ago when I was checking one of my production servers I saw that one of them had almost run of space and I wasn't notified about it. So I fixed the space problem, but I needed to find a fast solution in order to be notified if they reach a certain amount of disk usage.

I know the solutions like installing all kind of monitoring systems like Nagios, Cacti or/and installing something similar. In most cases that's the right solution, but in this case this server is pretty constant and it stays live only for legacy purposes and it will be terminated in a year.

In this machine I have PHP, Nginx and that's pretty much it. So here is my fast solution.
 
Read more

The power of 2 written in PHP

Not much to explain
function isPowOf2($int) {
    $logResult = log($int, 2);
    
    return ($logResult == (int) $logResult);
}

Flipping bits function written in PHP

In this post, I will show three solutions with benchmark test of flipping 32 bits unsigned integer's bits.
Three implementations can be seen below, they are named flippingBits1, flippingBits2 and flippingBits3.
The tests were executed 1000000 times flippingBits with follow inputs: 1, 23423, 234112321321313.

I executed on brand new machine several times and I find out average result, which is:
flippingBits1 - executed for 1.122 seconds.
flippingBits2 - executed for 27.193 seconds.
flippingBits3 - executed for 15.628 seconds.
 
Read more

Finding the most common character in a string written in Go

Few days ago I started experiments with GO language and I decided to resolve one problem with it.
There is my first function on GО which search for most common character in a given string.
The goal was to work with cyrillic as well as latin for that. Тhe code below will explain the rest.
func getTheMostCommonChar(text string) (string, error) {

	var textLen int = utf8.RuneCountInString(text)

	if textLen == 0 {
		return "",  errors.New("Empty string given")
	}
 
Read more

MySQL connection via SSH getting ‘reading ini…… packet’ error.

If you access MySQL through SSH tunnel and get "ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0" error, this can be indication for a lot of problems, but one of the weirdest is related by disabled “AllowTCPForwarding” option in ssh config.

By default in Ubuntu and Debian it's enabled, but some system administrators for security reason disable this option.

For enabling it again you must have root access or you can kindly ask your system administrator to do it for you.
In different Linux distribution it's my be in different place, but in Ubuntu and Debian it's at /etc/ssh/sshd_config.