Persistent connections for PHP sessions stored using Memecached

If you have a highly loaded PHP application server you probably came to conclusion to use memcached to store the PHP sessions, because files are too slow and generate many IOs. And when the session are enabled to be stored in memcached server the server could be overloaded with so many connections to the memcached instance(s) that the server could delay the creation of new connections to the memcached server and the server is in trouble even more than before with the file stored sessions.
The solution is to use persistent connections to the memcached server, so when a connection to the memcached is needed it will check to reuse an existing idle connection stored in a pool of connections so no new connection is created each time PHP needs something from the cache like the sessions. In fact PHP accesses sessions from the cache at least once for every request to the server and it could generate a pretty big number of opened connections.

On top of that there are two PHP modules, which offer objects or functions to use memcached server cache in your PHP code. The old module is called “memcache” (link) and the new one is “memcached” (link) – just to note these are the names of the PHP modules not to be mistaken by the server caching system “memcached”.

To configure the php-fpm or mod_php to store sessions in memcached caching server:

  1. use PHP “memcached”, this is the new and better supported module for using a memcached cache server. It supports the newer versions of PHP like 7+.
  2. use the following configuration added to your php.ini or the module ini file included in your php.ini (it really depends on your configuration, but if you are not sure put phpinfo() function in a PHP file and load through your web server – you’ll see the physical location of your php.ini file);
session.save_path = "PERSISTENT=1 localhost:11212"

Replace localhost with the server IP or leave it if the memcached server is on the localhost. This single configuration could decrease the usage of opened sockets from several tens of thousands (literally 30 000 – 100 000 and above) to couple of hundreds, which could have a great impact on system performance! (You’ll see it like a system usage time in your server graphs…)

*Worth mentioning the PHP configuration (php.ini file) must be edited to use memcached server for storing sessions:

session.save_handler = memcached

Install GO language in Ubuntu 16 LTS from the official site package

Ubuntu 16 LTS comes with too old GO language version, the version in the official repository is

golang-1.6.

Many programs released past couple of years depend on go lang 1.7+, so 1.6 in Ubuntu 16 LTS is really obsolete. At present the latest version is 1.9, so we’ll show you simple steps to install the go lang on your ubuntu 16 lts server

STEP 1) Get root if you want to install it globally to be used from any user!

sudo su
cd

STEP 2) Download the GO language binaries from the official site

https://golang.org/dl/

And copy the URL link of the program from the Linux section, now it has the following text:

Linux 2.6.23 or later, Intel 64-bit processor
go1.10.linux-amd64.tar.gz (114MB)

And download it with wget:

wget https://dl.google.com/go/go1.9.4.linux-amd64.tar.gz

STEP 4) Uncompress the file with “tar”

tar xzvf go1.9.4.linux-amd64.tar.gz

STEP 5) Move the files in “/usr/local/go”

you could put the installation anywhere, but most manual installed programs go to “/usr/local”

mv go /usr/local/

STEP 6) Set properly the environment to use your GO 1.9 installation

    • Create file with path and name

      /etc/profile.d/golang.sh

    • Make the file executable with
      chmod 755 /etc/profile.d/golang.sh
      
    • Insert the following line, which will add to the environment PATH your GO executable binaries
[[ -d "/usr/local/go" ]] && export PATH="$PATH:/usr/local/go/bin"

STEP 7) Reload the environment or just log off/in and check if you could execute the GO tool

root@srv.local:~# source /etc/profile
root@srv.local:~# go version
go version go1.9.4 linux/amd64

* Here are all the commands in one place to install the specific version of GO 1.9.4 AMD64, you can use them in a script:

cd
mkdir go-installation
cd ./go-installation
sudo wget https://dl.google.com/go/go1.9.4.linux-amd64.tar.gz
sudo tar xzvf go1.9.4.linux-amd64.tar.gz
sudo mv go /usr/local/
cat <<END | sudo tee /etc/profile.d/golang.sh 1>/dev/null
[[ -d "/usr/local/go" ]] && export PATH="\$PATH:/usr/local/go/bin"
END
sudo chmod 755 /etc/profile.d/golang.sh
source /etc/profile

And do not forget to

source /etc/profile

in your current shell session. It is mandatory for your current shell if you execute the above command from a script!

* This installation of GO Language 1.9 is from the official source the home site of GO Language. There are other easier ways to do it using, for example there are PPA repositories with Ubuntu packages ready to install, but they are not supported by the official GO team! Use them at your own risk as with all other PPA repositories.

PHP posix_kill missing in CentOS7

So you think you PHP code is running ok and your script for killing bad guys is perfect. Let’s assume you made a script to kill processes according to some criteria, put you script on your good all CentOS 7 server, but suddenly you encounter the error:

PHP Fatal error: Call to undefined function posix_kill() in ./kill-process.php on line 64
Killed process id: 21899
PHP Fatal error: Call to undefined function posix_kill() in ./kill-process.php on line 64
Killed process id: 21899
PHP Fatal error: Call to undefined function posix_kill() in ./kill-process.php on line 64

So you just missed a php plugin and there it is: “php-process”. Just install it with yum!

yum install -y php-process

And the error will disappear and the next time you want to kill some bad process you’ll sure do it!