Category Archives: Development

Flexbox cross browser

Despite having been around for a while and having been through a couple of revisions, its support across browsers can vary greatly. From “Candidate Recommendation” on Chrome/Opera, “legacy flexbox” on Firefox and no support at all on IE9 and earlier.

Making flexbox work consistently across browsers was a challenge for us on a recent project, but I have found a solution that seems to work quite well.

Below is an SCSS @mixin that will attempt to handle compatibility between CR and legacy cross browsers flexbox.

Firefox however only half supports flexbox (all revisions) and to get around this I would recommend using Modernizr as this will add the class “no-flexbox” to the <html> tag. This provides us with a simple work around that allows non flexbox supporting browsers render correctly by using specifically crafted and targeted CSS for non-flexbox browsers

I found that IE9 support could be implemented using the flexie javascript plugin. In IE8 Modernizr will add the class “no-flexboxlegacy” which can again allow you to create targeted CSS that wont affect your Flexbox layout.

For a great overview of the “CR” of flexbox, CSS Tricks has an amazingly comprehensive coverage of the functionality here http://css-tricks.com/snippets/css/a-guide-to-flexbox/

 

Bookmark and Share

Creating Custom Routes in Silverstripe 3.1

We wanted to create a Route to our custom Products Controller in our products module for SilverStripe 3.1, such as: “http://www.examplesite.com/products/<product-slug>”

However looking at the Controller Documentation it was not clear how to create a route without an Action being supplied. In our example above the action is not specified, as we just want to use ‘view’.

Solution:

Create a <module-name>/_config/routes.yml file containing the following:

The above will redirect any Url that starts with “/product” to our Product_Controller. Note that everything after the rule, so after “/product”, is used in the next bit for matching.

Now we need to add private static $url_handers to Product_Controller to match our path, so in this example we need to match “$Slug!” which will match “<product-slug>”. Note the ! means the slug is required. Of course we want to direct this to a specific action, in this case “view”, this gives us:

Now just add “view” to the $allow_actions and add the “view” function. This gives the final Product_Controller as follows:

Handy note:

You can put ?debug_request=1 on the end of your URL to see how it determines which Controller to use.

Bookmark and Share

Set up SilverStripe 3.1 using only Git (No Composer)

We recently tried to use composer to set up SilverStripe 3.1, but ended up with a dependency nightmare. In order to work around this we decided to make use of Git submodules.

First set up your Git repository and run:

Next set up a site directory for the code inside your Git repository. Then navigate to SilverStripe Installer in your browser and Download a copy. Extract files, and copy contents to site folder. Now we need to add the CMS and Framework. Navigate in a browser to the Git Hub repositories for CMS and Framework. Now copy the HTTPS clone URL for each project and run the following, to add these as Git sub modules.

Now delete mysite/_config.php and load the site. Follow the normal install instructions displayed and you will have a running version of SilverStripe 3.1

Bookmark and Share

Enabling MYSQL_CLIENT_INTERACTIVE with Doctrine 2 on Rackspace Cloud Database

We recently ran into problem using Doctrine 2 connecting to a Rackspace Cloud Database using the MySqli Driver.

Problem:

We have a long running PHP script that can sometimes run for hours at a time whilst processing information. This script requires a connection to a database, but has long periods of inactivity where there is no actual interaction with MySQL. By default MySQL uses the “wait_timeout” setting which states, how long an inactive connection can exist before it is killed. This is normally fine with web pages requests, as it is usually a short lived request. Unfortunately you do not have the ability to alter this setting when using Rackspaces Cloud Database.

Solution:

When using the MySQLi extension you can create a connection in “interactive mode” by passing the “MYSQLI_CLIENT_INTERACTIVE” flag, which will then use the “interactive_timeout” setting. On Rackspace this is set to 8 hours!

Annoyingly Doctrine does not allow you to pass any flags to the MySQLi Connection. So we overrode Doctrine\DBAL\Driver\Connection with our own Driver which then allows us to pass a “flags” parameter through.

Feel free to look at some of the other helpful features in we have added to Doctrine 2 here: ZucchiDoctrine

Bookmark and Share

Installing PECL extensions for Zend Server 6

Recently we have revisited using Zend Server for some of our projects and decided to give the new version 6 a chance to prove itself.

Overall its a big improvement over version 5. There are still some things that are extremely annoying but we have decided that we can overlook them.

However there is one thing that we couldn’t do without. By default you will find that a number of PECL extensions will not install out of the box (at least this is what we experience using the Debian based install).

To fix this you will need to make sure you install the additional packages in ubuntu

  • php-5.4-source-zend-server or php-5.3-source-zend-server depending on the php version you are using
  • autoconf
  • build-essential

Once this is done you should now be able to install extensions from PECL without too much hassle.

Bookmark and Share

Better Output for MySQL Select Command Using \G

If you ever find yourself using MySQL via command line and end up with something like this:

mysql-command-line And thought there must be another way, well here it is: Use \G instead of ; at the end of your select command.

For example:

Below is an image of the output from this select:

mysql-nice-output

Happy Querying!

 

Bookmark and Share

Introducing ZuQ – A Simple ZeroMQ Queuing Daemon

We recently had the need to create a queuing system to replace an implementation of RabbitMQ that was being used on a previous project. The reasoning behind this is that the requirements of the project required a very custom implementation of a queuing system that would drastically alter in architecture as the project grew and RabbitMQ just wasn’t going to fit the bill. However to start with we required something super simple and efficient that could be expanded and developed as required. After a little investigation and a lot of recommendation from others we decided to use ZeroMQ as our transport layer for that very reason, as we could build something which could span across multiple servers and was fast.

Continue reading “Introducing ZuQ – A Simple ZeroMQ Queuing Daemon” »

Bookmark and Share

Glorious Gluster – How to setup GlusterFS on Rackspace Cloud and Ubuntu 12.10

A few of our projects recently called for a distributed file-system that provided high availability and redundancy. After a tip off from a fellow techie and a quick browse around the net it appeared that a solution called GlusterFS appeared to tick all the boxes for what we were wanting.

However setting it up turned out not to be as trivial as I had originally anticipated. I’m going to try and put down the process we have evolved for setting it up on Ubuntu in the cloud

Continue reading “Glorious Gluster – How to setup GlusterFS on Rackspace Cloud and Ubuntu 12.10” »

Bookmark and Share

Docblock, Oh Docblock, wherefore art thou Docblock (hint: Zend Optimizer Plus lost them)

tl;dr> I make a terrible assumption about Zend Optimizer+ and am corrected by Dominic in the comments;

Terrible post title I know but its the best I could come up with.

I’ve just come up for air after spending the majority of the day debugging some issues on our current development sandbox.

Now our sandbox tends to be quite bleeding edge in some circumstances and as such we run a fair few bits of unstable code. On the sandbox in question we have been running PHP 5.4.11 and unfortunately we have struggled to get APC working with it just the way we need it to. The lack of APC tends to make this sandbox quite slow.

We recently saw that Zend have open-sourced their OptimizerPlus extension (https://github.com/zend-dev/ZendOptimizerPlus) and that it was compatible with 5.4…. Fantastic, or so we thought.

Continue reading “Docblock, Oh Docblock, wherefore art thou Docblock (hint: Zend Optimizer Plus lost them)” »

Bookmark and Share