Moving to the cloud part 2: Enabling database session storage

By default, PHP persists every user session to a single file stored in the system’s default temporary directory. You can go there, open an arbitrary session file – most likely prefixed by sess_ – and you will find a serialized array which represents the contents of the global $_SESSION array which is available to your scripts. Ok, this works great, so what’s the problem with this setup?

Actually, there is nothing wrong with using the file based session storage. But with growing demands some downsides of this approach may attract your attention:

  • The system’s temporary directory is a shared directory: session files of different applications  and temporary files of foreign processes may also use this location. In case of a security issue your user sessions may be compromised. This may be solved by configuring a unique session save path per application and put an open_basedir restriction on top to prevent unauthorized access. This applies all the more if your application is installed on a shared server. In contrast, a database can make use of its access management, you will just need to setup an excluvise account for your session table.
  • There are no simple means to increase file access performance. In constrast, a database usually knows a lot of concepts to improve performance like indexing and clustering.
  • As soon as you want to run your application on multiple servers for reliability and performance reasons you will prefer to store session data in a central location that is common to all webservers. Thus, every webserver shares the same pool of session data and it doesn’t matter which webserver of your cluster serves two subsequent requests of the same client.

Implementing a different session save handler in raw PHP is quite well described in the PHP documentation, so we will focus on how to do the Symfony2 configuration for this requirement. Continue reading “Moving to the cloud part 2: Enabling database session storage”

Moving to the cloud part 1: Intentions

Currently, we are moving our first Symfony2 application to the Amazon cloud (AWS). This series of articles describes how we modified and moved this application.

The existing application setup is a common one:

  • Single production server
  • Usual LAMP stack with Ubuntu and local MySQL database
  • File based sessions
  • User uploads stored in the local filesystem
  • Local Postfix mailserver
  • Cron jobs, e.g. for sending email reports
  • Deployment happens from a local machine using a self written deployment script
  • A little bit of monitoring using Nagios
  • Database backups using a self written script
  • File backups using duplicity
  • DNS management via client’s domain registrar
  • Git Version Control using Bitbucket

In the past, every programmer at our office has been more or less a one-man show, being the master of all the above mentioned processes. Continue reading “Moving to the cloud part 1: Intentions”

Aggregatsfelder mit Symfony und Doctrine

Dieser Beitrag handelt von einem Thema mit dem wir eigentlich schon oft zu tun hatten und auf die ein oder andere Weise implementiert haben. Und doch stellt es uns immer wieder neu vor die Frage wie man es eigentlich »richtig« macht, ganz abgesehen von Besonderheiten die jeder spezielle Fall mit sich bringt: Aggregatsfelder bzw. Aggregate Fields.

Continue reading “Aggregatsfelder mit Symfony und Doctrine”

Why I understand you are using ‘continue’ and why you shouldn’t

Recently I had to help out on a colleagues project, which I was not that familiar with.

First of all this ment to work the code and get a general understanding of what was happening. So after a while I found the spot where I had to put my changes. Implementation was done quickly enough and I was on my way testing.

First test didn’t give me anything. “Hmm.. this should work.. why am I getting no emails?”
Second test didn’t work the way I expected as well “Is my email sending broken?”
The third test was about my general ability of sending and receiving email. At least something was working the way I expected.

So it had to be the general function I was working at and naturally, revisiting the code brought the problem to light. My colleague used a rather cheeky way to abort the foreach loop, which prevented the function from ever reaching my newly implemented lines of code.

This is what I found up the lines:

Continue reading “Why I understand you are using ‘continue’ and why you shouldn’t”

Hello world!

“Hello world!” is probably the best possible title for the first post at a blog, which will mainly be about programming.

It represents everything, what the start into something new should be about:

Enthusiasm, hope, interest, curiosity, Abenteuerlust.

The Onemedia dev team actually planned for quite some time to start a blog. We talk alot about Symfony, the PHP eco system, good code, open source and the business in general. And if you talk alot about these topics you always have a thought or two to share. This shall become the place to share these thoughts.

To good times and many interesting interactions.

 

The Onemedia devs.