How to improve Symfony2 performance when running from shared folder on VM

Quite recently we, meaning PrepLounge, the startup I’m CTO at, got started on a new project and I chose Symfony as the framework to work with.

After reading the docs and running through the, fairly simply, install/setup steps I ran into a problem: Performance was really bad. A single request to the default controller (no changes where made to the AppBundle) took up to 8 seconds. This was unacceptable.

I googled about Symfony being slow and followed all the steps to improve the performance like:

  • Use bootstrap files
  • Enable APC for autoloading
  • Use composer’s class map functionality

Which is pretty much the same that’s listed on Symfony’s own site about performance improvements. And I even disabled Xdebug (on my dev system mind you, something unthinkable until now) in hopes that this might be the culprit. But all to no avail. Sure, every improvement shaved off a couple hundred milliseconds, but the best result I got was about 2 seconds per request. Which was still unacceptable.

I then dug deeper into the Symfony docs, trying to figure out how all the caching works and after reading how much file reading/writing is done for each request I started to suspect a completely different reason for the weak performance: My VM I use development.

My VM is a VirtualBox with Ubuntu 14.04 as guest system running on my MacBook Pro with OSX 10.11.1 as host. For all previous projects, the code always resided on the host and the VM gets access to it via shared folders.

And that’s exactly the problem. Apparently file reads/writes in shared folders are very slow compared to reads/write on the local file system. I had no idea. Sure, I figure there’d be some impact, but not that much.

Anyway, now that I had my suspicions I made some changes to my setup.

Previous setup:

  • Shared folder at /media/sf_project
  • Symlink from /media/sf_project to /opt/www/development/project
  • DocumentRoot at /opt/www/development/project/web

New setup

  • Shared folder at /media/sf_project
  • Actual copy of /media/sf_project at /opt/www/development/project
    • Updated every minute per rsync
  • DocumentRoot at /opt/www/development/project/web

And that did it!! Requests are blazing fast and take less than 100ms!

The only problem is, that the fastest a cronjob can run is once per minute. Which is probably fine in most cases, but for me as a developer to wait up to one minute for my changes to take effect is a nightmare! Especially when you are debugging or editing your CSS and only make small changes which you quickly want to check.

So I wrote a quick script that does exactly what the cronjob does: Run rsync to sync the folders and then set permissions. And then I updated the cron to run the script instead of having duplicate code. DRY ftw ;)

Here’s the script:


if [ "$1" == "" ]; then
    echo "Syncing project files..."
    sudo rsync -rptz --stats --exclude 'app/logs/*' --exclude 'vendor/*' --exclude 'app/cache/*' /media/sf_project/* /opt/www/development/project
    sudo rsync -rptz --stats /opt/www/development/project/app/logs /media/sf_project
    sudo cp /opt/www/development/project/composer.json /media/sf_project
    sudo cp /opt/www/development/project/composer.lock /media/sf_project
    echo "Setting permissions..."
    sudo rsync -rptz --exclude 'app/logs/*' --exclude 'vendor/*' --exclude 'app/cache/*' /media/sf_project/* /opt/www/development/project
    sudo rsync -rptz /opt/www/development/project/app/logs /media/sf_project
    sudo cp /opt/www/development/project/composer.json /media/sf_project
    sudo cp /opt/www/development/project/composer.lock /media/sf_project

sudo chown -R www-data:www-data /opt/www/development/project
sudo chmod -R 775 /opt/www/development/project

I called it “project-sync”, put it in /usr/local/bin and made it executable

sudo chmod +x /usr/local/bin/sync-project

Now, when calling it you can either simply use

project-sync silent

(actually any value as first parameter will trigger the silent mode) or, if you want more verbose output and info about what happend, simply run




I extended the cron to
a) ignore a couple of files I don’t need to copy since they don’t change locally (vendor, logs and cache files) and

b) sync a couple of files back into my local copy that I want to commit/need for debugging like composer-related files and the logs

I hope this is helpful to someone besides me :)

“Fix” phpMyAdmin timeout after 1440 seconds

If you are a regular user of phpMyAdmin like me, then you’ll have more than once had the problem of returning to your phpMyAdmin tab after a while and being prompted to login again, because you’ve been idle for 1440 seconds (=24 minutes). This is particularly annoying if you were in the middle of debugging something, e.g. with elaborate querys, but were interrupted by something or someone and now you have to start all over again!

Fixing this is actually quite easy and has been explained in detail by Brian Chang.

Be aware though, that you probably should not implement this “fix” on any servers that are accessible from the outside. Doing this on your dev machine, like the one from my tutorial, is a good idea though and something I’ll definitely add in its next iteration!

The more changes, the more stays the same!

It’s been a while, almost two years now, since my last post. Phew, let’s see how that happend (excuses, excuses..) and what’s happening in the future.

Pretty soon after my latest entry I went on a trip around the world for about 6 month and even though I fully intended to write weekly posts about cool stuff I did/encountered, I ended up not writing a single new entry. The trip was the best thing I’ve done in a long time though, so it definitely was worth it!

And once I got back, I was nearly overwhelmed by work. A lot of old projects needed maintenance and then a couple of big new projects came along and I simply lost sight and the interest in my blog. There was so much to do and so little time.

Now, two years later, I’ve re-discovered my interest for blogging/sharing and will try to do so on a more regular basis. Maybe actually do it once a week like I originally intended or at least a couple of times per month. They’ll probably not be the most extensive posts, but I’ll do what I can to keep them interesting.

So what’s going on right now/what has changed since my last post?

  • I’m still self-employed and working as a freelancer for serveral smaller companies/agencies. Even though I don’t need to be in any office or so and could easily work from any place I want to, I usually tend to stay at home and work from there. It’s what I’ve gotten used to and gives me the most flexibility in terms of working hours. I know there are quite a few people out there who can not work from home, because they get either easily distracted or want to keep work seperated from their private life. Both points I can understand, but so far it’s been working out fine for me…who knows for how long that’ll be the same :)
  • The site is at an all time high in terms of fake registration…
  • …and at a near all time low in terms of actual user activity. I guess I’ll have to spam some links on Twitter or so to get the traffic flowing again :)
  • I’ve switched from Prototype to jQuery. It’s been overdue for a long time and I’ve used the past year or so to get used to it and refine my skills. Absolutely loving it so far, so be prepared for a couple of jQuery related posts!
  • CodeIgniter 3.0 is still in beta/not released yet and it’s been like this for at least a year. I’m not sure what’s up with that, but I’m using it for all my current projects and it’s working like a charm.
  • I’m looking for a new PHP framework to base my projects on. CI has been fun, but I think it’s time to broaden my horizon and find something new/more advanced to play with. Laravel 4 looks really good, I think I’ll give it a try.
  • I’ve finally made the transition from SVN to Git. I have to admit I’m still not 100% sure about some things like branch management and such, but I’m getting there…I hope :) Most of my new projects are already hosted as private repos on Bitbucket and I want to start actually contributing to some open source software I’m using and give my own projects (mostly JS) a room for display. So keep an eye on my Github and Bitbucket profiles.
  • Inspired by some of the comments about my inital “Dev-Box” post, I’ve started experimenting with Virtual Box. Supposedly you can use the same VM on both Windows and Mac (which is important since I do work on both my MacBook and my Windows desktop machine and I want to share the development environment between them) and once I get the shared folder thing figured out, I’ll post a lengthy tutorial on how to get it all set up.

I think that’s it for now. Not too much after all, damn.

So here’s to more frequent updates on interesting topics! Cheers!

TortoiseSVN – Change User After Save Authentication

I had to update the credentials I use for one of the repos I work on but in TortoiseSVN there’s no built-in way of updating the saved credentials if the entered user is still valid (otherwise it will prompt you for a new username/password), except deleting all the saved authentication info for ALL repos worked on via TortoiseSVN.

After some research on Google I found this blog post by JohnnyCoder where he describes the same problem solved it using the above mentioned method of removing all the saved data. Lucky for me in one of the comments Brad Divine described a different approach which would only require you to delete a single file, the one holding the credentials for the one repo you want to update instead all of them. Sadly his approach didn’t work for me but with a slight adjustment to the path he mentioned I got it working on my Windows 7 system:

Go to this folder:


The files you find here can viewed in any text editor and each file holds the credentials for one repository. They all have cryptic names but you can manually open them all and find the one you are looking for real quickly. Once you got it, just delete the file and next time you want to commit or update your local copy, TortoiseSVN will ask you for new credentials.

In case you are wondering, the folder for XP users looks like this:

C:\Documents and Settings\<your-username>\Application Data\Subversion\auth\svn.simple\

Dev-Box: mod_rewrite and Virtual Hosts for your Apache

This is gonna be a quick one, but I think you’ll find this quite useful … if you don’t already know it by heart ;)

As I promised in my initial Dev-Box post, I promised to give further useful instructions/tips for your development VM, so here we go: mod_rewrite and Virtual Hosts for Apache. Two basics that every coder should know by heart and uses every day (even though he might not be aware of it). I, for example, create a virtual host for every new project I start. That way I can access them easily via their own URL and don’t have to remember the exact folders they reside in.

Continue reading Dev-Box: mod_rewrite and Virtual Hosts for your Apache

Dev-Box: Installing a Mail Server

It’s been a while, but I’m back with another useful tutorial for all those out there using VMs like my Dev-Box. Last time I talked about getting SVN to work on your VM and now time it’s all about setting up a mail server, something you need for pretty much every web application you might develop.

As my posts are meant for users that use VMs for local development, I’ll not tell you how to install a usual mail server, but rather how to configure it that way, that all outgoing emails go to one email address instead of the address they are meant for. Using such a catch-all setup allows you to test emails coming from your app without having to send mails to existing accounts and even allows you to use your live database for testing and not having to worry that the live users might get an email that’s only meant for testing.

Continue reading Dev-Box: Installing a Mail Server

Dev-Box: Installing SVN

My last post about setting up a Virtual Machine to use as your local webserver was quite the success (hits increased from about 30 to nearly 1000 within 2 days…and dropped back to somewhere slightly above the old value by now) and I promised I would write some more tutorials on how to install some useful libs, so here we go and start with SVN in combination with TortoiseSVN a SVN client for Windows.

Continue reading Dev-Box: Installing SVN

Dev-Box: Virtual Machines for Developers

This post goes out to all the coders using a Windows machine for development. Might be interesting for others aswell but I can’t say much about that as I’m a Windows user myself ;)

So what is this about? Well, some time ago I ran into smaller problems when trying to move a website from my local machine (which used XAMPP) to a real server (which was running on Ubuntu or some other Linux distro) and it was hard to fix the problems because of the differences between Windows and Linux servers.

I talked about this with a friend of mine and he told me about Virtual Machines (=VM). I had never heard of them before but what I heard was intriguing. Virtual Machines allow you to run a machine inside your machine, e.g. a Linux server inside your Windows machine. So you can use this VM with Linux to test your website locally before moving it to the real server. I know that no server is like the other and you might still run into some problems due to different library versions and so on, but you gotta admit that two Linux servers have way more in common than a Linux and a Windows server ;)

So in this post I’ll tell you how to setup your own VM with all the libs you need. Even if you haven’t worked with Linux before, you should be able to follow this tutorial/example easily.
Continue reading Dev-Box: Virtual Machines for Developers


A while back a friend of mine mentioned this site to me: It checks which porn sites you have been on.

The technology used to achieve this is quite simple. It inserts links to a bunch of porn sites in the page and uses Javascript to check the link color, abusing the fact that browsers by default use different colors for links you have visited or have not.

Some days ago I came across a blog post by David Walsh in which he described how to perform the above described check using jQuery. I was amazed how easy that was and thought it must be equaly easy to do the same using Prototype. Well, here we go:

I’ve set up a demo that checks a small number of sites (no porn, sorry).

Here is the small function I use to do the checks:

  var a = new Element('a', { href: 'http://' + site, }).addClassName('check').insert(site);
  if(a.getStyle('color') == '#800080' || a.getStyle('color') == 'rgb(0, 128, 0)') {
  } else {
   var b = new Element('a', { href: 'http://www.' + site }).addClassName('check').insert(site);
   if(b.getStyle('color') == '#800080' || b.getStyle('color') == 'rgb(0, 128, 0)') {
   } else {

with siteList being an array of sites that will be checked. The basically creates an anchor element for each site in the array and checks that elements color. If it matches my defined css style for visited links, than I add the class name ‘highlight’ to the element, otherwise I don’t. That’s pretty much what David Walsh does aswell, but additionally to that I check both and as some might have visited the one but not the other. If none were visited, I show the link.

Any questions? No? Then start abusing this ;)

P.S.: This is an older post I copied from my old blog. Thought some of you might find this useful.

Extended logging of database errors in CodeIgniter

Some of you might and now and then have run into a database error while working with CI. Such errors are mostly caused by errors in your querys like not escaping user input or your fields or simply syntax errors.

In small applications that not much of a problem, but the bigger the application the harder it get’s to find the part where the bad query is hiding.

dootzky from the CodeIgniter Forum had exactly that problem and with a little help from wiredesignz we were able to add some more detail to the error messages!

Simply add this to the body of ‘application/errors/error_db.php’:

if($_SERVER['HTTP_HOST'] == 'localhost') {
   $trace = debug_backtrace();
   echo "The error occured in file ".$trace[4]['file']." on line ".$trace[4]['line']."";

Now additionally to the error you already know, you will be shown in which file and on which line the error occured (the db->get() method was called)! As this might pose a security risk on live systems, dootzky added the check for localhost.

I know that with CI 2.0 this might be obsolete because the error messages were enhanced, atleast the database errors now show filename and line, but someone still using some older version of CI (like I do for most of my older projects) might still find this handy.

P.S.: This is an older post I copied from my old blog. Thought some of you might find this useful.