Storing your PHP sessions using memcached

http://www.dotdeb.org/2008/08/25/storing-your-php-sessions-using-memcached/

sudo apt-get install memcached
sudo apt-get install php5-memcache

and change some of your PHP settings :

sudo nano /etc/php5/apache2/php.ini

session.save_handler = files
; session.save_path = "N;/path"

to :

session.save_handler = memcache
; change server:port to fit your needs...
session.save_path="tcp://localhost:11211?persistent=1&weight=1&timeout=1&retry_interval=15"

sudo service apache2 restart

To see if its working:

http://www.mycreativity.nl/blog/setting-up-memcached-on-my-raspberry-pi/

echo "stats settings" | nc localhost 11211

This shows that the Memcached is now listening on port 11211 with localhost connections only. We will change this to the, catch-all, IP 0.0.0.0 by changing the line: “-l 127.0.0.1” to “-l 0.0.0.0” in the file “/etc/memcached.conf”. After changing the config you can see if we can now make a connection from external machines use the following command:

netstat -ln4t | grep :11211

Raspberry PI + Extend SD card life

http://raspberrypi.stackexchange.com/questions/169/how-can-i-extend-the-life-of-my-sd-card

sudo swapoff --all

You must also prevent it from coming back after a reboot:

  • For Raspbian which uses dphys-swapfile to manage a swap file (instead of a “normal” swap partition) you can simply sudo apt-get remove dphys-swapfile to remove it permanently. Best to remove because setting the CONF_SWAPSIZE to 0, as explained in this answer, doesn’t seem to work and still creates a 100MB swap file after reboot.

Directories in RAM

Highly used directories such as /var/tmp/ and possibly /var/log can be relocated to RAM in /etc/fstab like this:

tmpfs /var/tmp tmpfs nodev,nosuid,size=50M 0 0