Tuesday, June 25, 2013

Using Memcached with Symfony 2 (on CentOS 6)

The biggest problem, that I've been running into for years, is always performance. But sometimes optimizing your code isn't good enough, sometimes because you're depending on external libraries, which you don't want to change.

For one of our customers, I ran into this problem as well, so I had to find a solution. I've already heared about Memcached often, but I never had the time to look into it and I was kinda scared to have to implement it in an already existing application. Afterwards, I found using the basics of memcached was pretty simple, and it boosted my page speed by 50-75%(!), only by caching doctrine queries and results.

A quick Google search found me a bundle that claims to do exactly what I want: the LswMemcacheBundle. LswMemcacheBundle is developed by LeaseWeb, which leverages the power of the PHP 'memcached' extension (not the older 'memcache' PHP extension, the d make a huge difference as explained on http://code.google.com/p/memcached/wiki/PHPClientComparison).

The installation instructions looked quite simple: install memcached, install the memcached extension and add one line to your composer.json. For Debian based systems this is the case, but CentOS 6 has some obstacles in place.

With CentOS 6 there are a couple problems:
  1. The php extension 'memcached' requires libmemcached. Unfortunatly the version of libmemcached in yum is to old to meet the requirements
  2. The php memcached extension can't be installed trough yum, so this has to be installed trough pecl
  3. Installing the php memcached extension trough pecl threw some errors while compiling.

Wednesday, February 6, 2013

Using master and slave databases with Symfony 2 + Doctrine

One of our customers works from different locations in the Netherlands, but with their backoffice on a server in south-east Germany and an extra penalty caused by the crappy internet connection, this can sometimes be very slow.
So the first thing I thought of to solve this is to run a mirror of their backoffice on location. Setting up the MySQL replication[1] and automatic syncing of files[2] was easy. But then my code had to be adjusted to work with a Master server (the server in Germany) and a Slave server (within the local network).
For those of you unfamiliar with the concept of Master and Slave database servers: The idea is is to have multiple database servers, one Master server (who 'owns' all the data) and one, or multiple, Slave servers, who receive a copy of all the changes from the Master server. The Master server needs to be accessible to all the Slave servers (i.e. via the internet), but the Slave servers can be servers within a local network.
When I started my search on the internet for information on how to achieve this, I found many complicated solutions, including solutions that told you to change vendor code, to write custom connection classes etc. But I figured there had to be an easier way and (thankfully) I was right.

Thursday, December 20, 2012

Solution: Crack the code (Dead Trigger code-puzzle)

Since the contest is over, it is time for me to reveal the way I figured out to solve the code.

SPOILER ALERT!

Wednesday, December 19, 2012

Crack the code (Dead Trigger code-puzzle)

One of my favorite mobile games (Dead Trigger) recently launched a challenge. You can find a code in there game and the first 10 to decrypt it will receive a T-shirt. Before I share the solution with anyone, I'd like to give you a chance to crack the code as well:

02201010121021210121111011020201012110221021210202010121022210202111111102101012110101021001012021121020210121110221021201012101211100210201010121101010210010120220010121102011020211021012010101202112101211111101012021120101202021010120121201210012110121201211012120121201211

Good luck all.

P.S. Just got the confirmation I was lucky to be among the first 10 :-). I'll post a picture of the shirt as soon as it comes in.

Friday, December 7, 2012

Bundle for faster generation of entity dropdowns for Symfony 2

Soon after writing my previous blog, where I described a way to speed up the rendering of entity dropdowns, I received lots of feedback about better and nicer ways of doing this. All the suggestions where the same: use a custom form type and a datatransformer.

So I did for one entity, but I didn't feel like doing it for every entity. So I wrote a console command that allowed me to do this automatically (for one or all entities within a bundle).

After a short discussion with my boss, we agreed upon releasing the generator to the public and today the day is here.

The bundle is located at https://github.com/TheDevilOnLine/Symfony-FastEntityBundle and can be installed via composer. For all the details please take a look at https://github.com/TheDevilOnLine/Symfony-FastEntityBundle/blob/master/README.md

Oh and feel free to say thanks to my boss (Martijn) in the comments, for allowing me to opensource otherwise proprietary code.

P.S. This is my first time releasing code using composer, so please report any bugs you might run in to on GitHub: https://github.com/TheDevilOnLine/Symfony-FastEntityBundle/issues

Thursday, November 22, 2012

Speeding up the rendering of entity dropdowns in forms in Symfony 2

Update: See http://12wiki.blogspot.nl/2012/12/bundle-for-faster-generation-of-entity.html for an improved implementation.

One of the great features of Symfony 2 is the simplicity of rendering a form, even when you're using external entities. The only problem is that rendering a dropdown with 3662 entities is quite slow. In my case this took almost 2 seconds!

Wednesday, November 21, 2012

How to time your own events in Symfony 2?

As some of you might have noticed by now, I am quite interested in the performance of my application. Since Symfony 2 has such a great profiler I was looking for a way to time my own code within the existing profiler and without writing to much code.