Archive for July, 2010

Using memcached to share PHP sessions

Posted in apache, memcached, php on July 29th, 2010 by fseek – Be the first to comment

This tutorial explains how to install and configure memcached to share PHP sessions across multiple servers (all running CentOS).

One of my sites was outgrowing the cheap VPS server that we were paying for it. Instead of adding more memory/CPU, we decided to add more servers to the equation, sharing the load between them.

To do that, we started to use memcached. Memcached is very simple to use and install and is easy to integrate with PHP. Let’s get to work!

1- Installing memcached.

Memcached has some prebuilt packages for Ubuntu, but none that I could find the CentOS. Because of that, I had to install it manually from the source. It is simple as well, just follow these steps:

1.0 – Installing pre-requisites:

# yum install libevent-devel.i386
# yum install php-pecl-memcache.i386

1.1-Downloading:

# wget “http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz”
# tar -zxvf memcached-1.4.5.tar.gz
# cd memcached-1.4.5

1.2-Compiling

# ./configure
# ./make && make test
# ./make install

1.3- Running it

# /usr/sbin/useradd memcached
# /usr/local/bin/memcached -d -u memcached

You see that we installed it at /usr/local/bin and created a restricted user for it. Now you should have memcached running. Just run “netstat -tanep” to check.

2- Configuring PHP

2.1 – Via php.ini

If you have access to the php.ini (like we had in one of our servers), just add the following to it:

session.save_handler = memcache
session.save_path=”tcp://serverA:11211″

After restarting Apache, PHP will use memcached that we installed on the “serverA”. That’s all.

2.2 – Via modifications in the php scripts

If you can’t modify your php.ini, add the following to your php scripts:

ini_set(’session.save_handler’, “memcache”);
ini_set(’session.save_path’, “tcp://serverA:11211″);

That’s it as well. If you are having problems with the sessions, make sure to use the same session name across servers:

ini_set(’session.cookie_domain’, “.domain.com”);
session_set_cookie_params(0, ‘/’, ‘.domain.com’);
session_name(“SESSIONX”);
session_start();

That’s it. Easy, no?

GPL and the Wordpress x Thesis theme issue

Posted in licenses, wordpress on July 15th, 2010 by fseek – 10 Comments

Quick update: It seems that Thesis is actually using parts of the GPL Wordpress code. I don’t have access to the code now, but if they are using, then Matt is right and Thesis is violating the GPL. If they are not using Wordpress code (just the API calls), then my argument remains.

I am hearing a lot about the dispute between Matt Mullenweg (from Wordpress) and Chris Pearson (from the Thesis theme).

You can listen/read about the dispute here:http://mixergy.com/chris-pearson-matt-mullenweg/

The issue is that Matt (and a big part of the open source/Wordpress community) thinks that themes should follow the same license as Wordpress itself (GPL), while Chris thinks he can use any license he wants.

There is one big thing about this debate that most people are missing: The issue is not about the GPL or about what Wordpress thinks, but about what a derivative works means and if a theme is a derivative work or not. That’s what the GPL says:

These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.
But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

 

If Thesis is not a derivative work from Wordpress, it doesn’t have to follow the same license as Wordpress. Linux modules doesn’t have to be under the GPL just because Linux itself is licensed under it (in fact, there is many closed-source Linux modules out there). If a software just uses a public API (which could be considered the same as executing commands on the terminal), it is not a derivative work. It merely integrates with that software.

A few facts:

1-Thesis do not include any software from Wordpress.
2-Thesis do not distributes any part of Wordpress.
3-The code is based on their open/public API, used to integrate the Theme with Wordpress.

How can that be different from me running a command on my bash terminal or using Linux? Nothing.

Also, in the interview, Matt mentioned that “GPL won” a few cases against Cisco (and other big companies), but in none of the cases so far the dispute was over the slim line of a derivative work. They were using and selling an open source software and not following the license. Different then Thesis that does not distributes Wordpress.

Yes, you can see that I agree with Chris on this issue. I don’t know him or ever used the Thesis theme. I am big open source fan, but we have to be fair.