PHP, Web Development, Yii Framework

Stop Newrelic from recording slow AJAX/general calls in Yii2

I recently had to stop Newrelic from recording my long polling tactics so I came up with:


namespace common\components;

use Yii;
use yii\base\Component;
use yii\base\BootstrapInterface;
use yii\web\Application;
use yii\web\Controller;

class Newrelic extends Component implements BootstrapInterface
	public $ignoreRoutes = [];
	public function bootstrap($app)
		// delay attaching event handler to the view component after it is fully configured
		$app->on(Controller::EVENT_BEFORE_ACTION, function () use ($app) {
	public function beforeAction($app)
			if(in_array(Yii::$app->getUrlManager()->parseRequest($app->request)[0], $this->ignoreRoutes)){
SEO, Web Development

Should search pages be blocked in robots?

I recently got a problem on a site I co-manage whereby Goolge Webmaster Tools suddenly stated one day, after some extensive crawling, that the site had far too many URLs.

In the list I saw many search result pages and after some investigation various links directed me to this page whereby, at the bottom, it says:

Typically, you should consider blocking dynamic URLs, such as URLs that generate search results,

where it states solutions.

So it seems that this, normally, grey area is quite black and white now-a-days and you should be blocking your search from robots, else Google could penalise you by not correctly crawling your site.

CSS, Web Development

Responsive images via background-size

As I was doing some image uploading work on a project recently I decided to understand, truly, if I should resize and cut corners off to keep ratio or thumbnail and keep the independant size of the image but risk making it difficult to put into the page.

As an example, I have an image of 700px x 418px. I have a choice between cutting it down to 400px x 400px cutting off 300px or bringing it down to about 400px x 238px and make it more difficult to add to a Bootstrap powered gallery.

So I looked at what Facebook did here and I noticed they actually use the 400×238 image as a background image and then used background-size:cover to fix any problems. Forutnately, despite what ( says, background-size is supported on IE8 (I actually got a Win 7 VM with IE8 on it from and tested it) but, with no content, the media queries for resizing the colums could not function right.

So I need something to tell both IE8 and later browsers how to size this image.

The CSS solution at this link works pefect:

In short: here is the post summarised.

<div style="width: 400px">
    <span id="image">
        <span id="image-inner">

#image {
    display: inline-block;
    width: 100%;
    font-size: 0;
    line-height: 0;
    vertical-align: middle;
    background-size: 100%;
    background-position: 50% 50%;
    background-repeat: no-repeat;
    background-image: url(image.jpg); 

#image-inner {
    display: block;
    height: 0;
    padding-top: 63.3%;
PHP, Yii Framework

Getting Yii2 debug to show on user role instead of IP

I recently had to get Yii2 debug to show based on whether I was an admin user or not due to not connecting to the site using static IPs.

Having the debug in production run for the admin user is really useful for fixing those problems which are not easily, or possibly, replicated down to development.

So I overrode the Module class for debug but found some problems with view paths. I ended up with:


namespace common\components;

use Yii;
use yii\debug\Module as DebugModule;
use common\models\User;

class Module extends DebugModule
	private $_basePath;
	protected function checkAccess()
		$user = Yii::$app->getUser();

			$user->identity && 
			return true;
		return parent::checkAccess();
	 * Returns the root directory of the module.
	 * It defaults to the directory containing the module class file.
	 * @return string the root directory of the module.
	public function getBasePath()
		if ($this->_basePath === null) {
			$class = new \ReflectionClass(new yii\debug\Module('debug'));
			$this->_basePath = dirname($class->getFileName());
		return $this->_basePath;


The question of internet freedoms

I would say this film is required watching for all internet denizens:

It tells of a person who gave everything for the cause of internet freedom, even their own life.

Somethings have made me question free speech and freedom of information on the internet, for example: what is the difference between free speech and self advetisement? Is there an invisible line that should be drawn even on blog comments (such as this very site) between what is considered free speech and what could be counted as very elaborate spam to promote a certain product invisibly?

I have so far avoided censoring any blog comments on here, even ones that contain links to the commentors site or products within them, mainly because I feel so strongly about freedom in every single way that I feel bad about editing that comment, even if to just remove that link.

In an internet where people say they are for free speech ( but then use the very same motto and morale as Aaron to make free speech work for their own ends it is sometimes hard to decide if Aaron really did make a difference in the long term.

Take, as I mentioned, They boast free speech as being paramount to everythng they believe in, that it is required of every blogger on this site (they even produce transparency reports: and they try their hardest to confront every take down request and stop it. Yet they cannot seem to apply that rule to themselves, in the form of comment moderation on their news blog posts (it is kind of like a newsletter).

I have made many comments on news blog posts over my time here but only one has ever not been censored. I made a comment recently on Rwanda and how evidence shows that it is not only under a increasing, authoritarian, dictatorship (whose leader has been numerously accused by his closest allies of causing the action that resulted in the murder of many hundreds of thousands of people) but that ethnic grievances have never been solved, and how the problems are just laying under the surface for a resurgance of voilence.

The comment was in line with the post which talked about using UX design in Rwanda to try and put across and message that massacres are wrong and that they should not be tolerated. I praised the author for his gumption to try and do something but reminded people of the facts that are beginning to once more make themselves aware.

This comment was consequently consored and deleted along with many other less confrontational comments, even ones as simple as “the website you linked has UX problems because…” on a more recent post of what they considered to be good looking websites; ironically they allowed comments through which agreed with their stance.

This explains the problem quite clearly, many people on the internet are using Aarons legacy as a means to pass themselves off as pro-freedom, pro-sharing, when in reality they are not. In reality they use and abuse Aarons and other legacy to suite their needs, and turn back to the old ways when it no longer suites them.

Freedom is not about it suiting you, it is about you respecting and understanding other peoples wantings and needs. When someone comments on your blog post, don’t remove what you don’t like, it is their needs that they feel as though they have to say that. Yes, I understand there are limits, swearing, abusive language, and the rest. However, when someone genuinely makes a worthwhile comment on our site/blog you should try everything in your power to accomodate for their need of freedom, including free speech.

We have created an amazing thing called the internet, people have even died to give us the freedoms we currently enjoy on the internet; you could even count those that died in the World Wars as being part of that, afterall is not the internet based upon our own principles of freedom? However, there are those who will use this legacy to their benefit to twist the internet into their own little playground and attempt to tame it. It is bad enough that our internet is run by a bunch of technologically senile people who cannot call us “experts”, let’s not prove that we are no better by resorting to freedom by convience.

Next time someone tries to comment on your blog remember the likes of activitists like Aaron who tried to give you the right to make that content in the first place to be commented on.

Try to keep our freedoms.