Skip to main content

Posts

Compressing Apache output with mod_deflate on Centos

Apache on Centos ships with mod_deflate installed and enabled by default.  To check this you can grep your config file and make sure the line which loads it is not commented out. cat /etc/httpd/conf/httpd.conf | grep LoadModule deflate_module When Apache loads it reads all the config files (ending in .conf) in /etc/httpd/conf.d so we'll add configuration options for mod_deflate into this directory. Lets use a file called deflate.conf to specify the config: <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutput...

Separating business logic from persistence layer in Laravel

There are several reasons to separate business logic from your persistence layer.  Perhaps the biggest advantage is that the parts of your application which are unique are not coupled to how data are persisted.  This makes the code easier to port and maintain. I'm going to use Doctrine to replace the Eloquent ORM in Laravel.  A thorough comparison of the patterns is available  here . By using Doctrine I am also hoping to mitigate the risk of a major version upgrade on the underlying framework.  It can be expected for the ORM to change between major versions of a framework and upgrading to a new release can be quite costly. Another advantage to this approach is to limit the access that objects have to the database.  Unless a developer is aware of the business rules in place on an Eloquent model there is a chance they will mistakenly ignore them by calling the ActiveRecord save method directly. I'm not implementing the repository pattern in all its ...

Using multiple accounts with Github

If you're like me and have a personal Github account but work for a company that also uses Github you will probably want to be able to set up multiple accounts on Github. It's pretty simple to do so: Firstly you need to create a new key for your company account. Make sure that you save it to a file other than the default id_rsa otherwise you'll overwrite your default ssh key. For illustration lets save it to ~/.ssh/id_rsa_alternate ssh-keygen -t rsa -C "your-email-address"   Now open up your company account on Github and navigate through the settings to manage your ssh keys.  Use the following command: cat ~/.ssh/id_rsa_alternate.pub   Copy and paste the output into a new key on your company Github account. Next we add the new key to our identity: ssh-add ~/.ssh/id_rsa_alternate Edit (or touch) your ssh config file at ~/.ssh/config and include a new option for authenticating using your company account: Host github-COMPANY HostName...

Caching Laravel with Varnish

PHP Framework popularity as at 2013 - Sitepoint After having a very good experience with using Varnish to cache a Wordpress site we decided to look at caching Laravel. Laravel always generates cookies regardless of whether a person is logged in or not.  This interferes with Varnish which by default will pass all requests with a cookie to the backend and skip the cache. In our particular case our site supported the ability for users to login and would then present them with custom content.  This means that cookies are not restricted to a particular path so we can't discard cookies based on the request as we did for Wordpress when discarding everything except /wp-admin/* requests. My solution was to use a package called session-monster ( Packagist  ) which sets a response header if the data in the Laravel session can be ignored.  Varnish can detect this header and prevent the cookie from being set since we don't really need it.  This together with t...

Wordpress on Hiphop / Nginx / Varnish

I recently was asked to investigate speeding up one of the Wordpress sites of a fairly large government organization in Britain.  A large part of my investigation focused on the server stack because I felt that we could get more out of the hardware that was provisioned for us. I decided to set up a stack on my development machine to see how it would work and if it was feasible.  I settled on nginX with hiphop and a Varnish frontend cache.  I realize that nginX would be just fine as the cache and server but in this particular case it would not be possible to replace Apache with nginx on the live server.  I also wanted to experiment with ESI and it looked better documented in Varnish than nginx. Installing HHVM is very easy: wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | apt-key add - echo deb http://dl.hhvm.com/ubuntu saucy main | tee /etc/apt/sources.list.d/hhvm.list apt-get update apt-get install hhvm Installing nginx is also very easy:...

Server sent events in PHP

Server sent events are really pretty cool.  They let your application function a little bit more like an application and a little less than a click adventure in the web wonderland.  They are very simple to code and allow your backend code to notify your frontend of progress or other changes. I could get into trouble for this class comment At time of writing they are not supported by Internet Explorer ( see here ) but hopefully Microsoft will either stop making Internet Explorer or bring it up to speed with modern browsers.  Yeah I know that's not going to happen, but we can wish right? You don't need to retain an open connection for every visitor to your site because browsers will reopen a closed connection after a few seconds.  The additional load for implementing SSE seems to be manageable according to people like this guy who have done tests. My first project implementing them was for a database consistency tool that is intended to be run against the d...

Useful tool when helping Windows users install their OS

This post is more of a "note to self" than an attempt to be useful to somebody else. I am even typing this post in Internet Explorer. It feels like a Pterodactyl is about to swoop into the room and try to shit on HTML standards. In any case I gave my backup laptop to my kid and so had to install Windows on it. Why? Well I want her to be able to play games so Windows seems the best choice. Plus she can still learn open source programming languages, albeit in a funny way. Luckily I remembered this blog that I read and they posted this really nifty tool called Ninite. Click the link here ( http://ninite.com/ ). This helpful tool lets you download a single install file that installs free (either OSS or free to use) software like Libre Office, Flash, Notepad++, antivirus, etc. Lets just say that it feels almost like an Ubuntu meta-package that helpfully installs everything you need, but you get to choose. Plus it's all free and the only software I don't tr...