Posts Tagged ‘PHP’

MSVCR110.dll errors when running PHP

Thursday, April 9th, 2015 | Tech

If you attempt to run php.exe on Windows you may get an error involving the following DLL.

MSVCR110.dll

The resolution to this is to install “Visual C++ Redistributable for Visual Studio 2012 Update 4”. Note that you should install the 32-bit version even if you are using a 64-bit operating system!

This can easily catch people out first time, however you can just install the 32-bit version over the top.

Enabling Agile through enabling BDD

Friday, March 7th, 2014 | Events, Tech

Last month I attended a Leeds PHP event where the guest speaker was Konstantin Kudryashov, author of Behat. He made a great case of how using BDD can really help you stay on track with the agile process.

Unfortunately I was sat directly behind a massive dan boy who spend the entire time enthusiastically nodding to everything that was said. I am sure he is a nice guy, it was just very distracting.

Richard had a very different opinion. He described most of what BDD did was nonsense. It works fine on your Symfony2 stack, but it just adds massive overhead for little benefit he argued, citing an example of how the company he is working with at the moment has just ripped years worth of it out.

I know what he means. It does work great on some stacks but become difficult on others. Also, I was working with a company that had done half their unit testing in it. I will not mention which mayor subscription TV company that was, but it was a great example of applying Behat to the wrong use.

However, on the whole I think BDD really can add a huge amount of structure and benefit to a product. You can knock “value” as a buzzword, but actually it just means actually focusing on what makes a product better and that genuinely is all that matters.

PHPNW13

Sunday, October 13th, 2013 | Programming, Tech

phpnw13

Last weekend I headed over to Manchester for PHPNW13.

I really enjoyed last year’s event and came away having learned a lot from it. This year was also quite interesting, though on returning home and reviewing my notes, there is only really one new thing that I want to look into.

PMA_Message not found in phpMyAdmin

Thursday, May 2nd, 2013 | Programming, Tech

You may get an error similar to the following in phpMyAdmin.

PHP Fatal error: Class ‘PMA_Message’ not found in /usr/share/phpMyAdmin/libraries/Message.class.php

This is caused when Apache is unable to create a session – perhaps because of a permissions issue on the session folder, or perhaps because you have run out of disk space.

Class constraints in Symfony2

Saturday, March 9th, 2013 | Programming, Tech

Sometimes you need to put a constraint on a whole class, rather than a single value. Duplicate usernames are a good example of this – you don’t want to be able to set a username to one that is already in use – but if it is in use with the user you are currently working on, you don’t want to flag it up as an error!

Lets use that as an example. You have a Username constraint and a UsernameValidator object to do the actual validation. We need to supply the validator an object, so we need to put the following method inside the Username object.

public function getTargets()
{
    return self::CLASS_CONSTRAINT;
}

This will turn the first parameter in our isValid function in the UsernameValidator class to an object.

public function isValid($user, Constraint $constraint)

Finally, you can call the constraint from your YAML validation file.

User:
    constraints:
        - nocs:UniqueUsername: ~

Normally, under user you would have getters and properties – but here we’re adding a new section named “constraints” which lists all the class constraints.

Validation in Symfony2 unit tests

Sunday, March 3rd, 2013 | Programming, Tech

Want to use the Validation module in your Symfony2 unit tests? No problem, thanks to the ValidatorFactory, it’s relatively straight forward.

use Symfony\Component\Validator\ValidatorFactory;

class ExampleTest extends \PHPUnit_Framework_TestCase
{
    public function testSomething()
    {
        $validator = ValidatorFactory::buildDefault()->getValidator();
    }
}

Simply include the ValidatorFactory namespace and then use the class and it’s default values method to deliver you a validator, which you can then validate your objects against just as if it was in a controller.

Installing Imagick on Ubuntu 12

Sunday, February 10th, 2013 | Programming, Tech

To install Imagick, you would normally do this via PECL.

sudo pecl install imagick

However, when trying this on Ubuntu 12.04 LTS, you may get an error similar to the following.

checking ImageMagick MagickWand API configuration program...
configure: error: not found. Please provide a path to MagickWand-config or Wand-config program

You can resolve this by installing a few extra packages.

sudo apt-get install libmagickwand-dev libmagickcore-dev

Now try re-running the original command and it should be successful.

Beanstalkd

Sunday, January 27th, 2013 | Limited, Programming

Do you need a work queue system but think a message queuing system like Rabbit or Active MQ would simply be too complicated? Probably not, but imagine you did. Enter Beanstalkd. The super simple work queue daemon.

I went down to Leeds PHP for the first time in a while last week, where there was a talk about Beanstalkd. It’s effectively a FIFO queue – you can put a message in the end, and have another process take a message out of the start, the effect being that you can take some of the load off server intensive processes, and do them later when you’re not busy.

I had a play around with it in PHP, using the Pheanstalk and it really is a simple as that to work. You create a connection to your Beanstalkd server, and then just push and pull messages from the various queues, that you can create on the fly, like Mongo.

Installing ImageMagick and Imagick on Mac OS X

Friday, January 11th, 2013 | Life, Tech

Trying to get ImageMagick and it’s PHP extension working on OS X Lion is a frustrating process. It will often fail and even if you try to configure it manually you may get an error like the following.

checking ImageMagick MagickWand API configuration program...
configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.

First of all, install ImageMagick via MacPorts.

sudo port install ImageMagick

Now install the imagick PECL module.

sudo pecl install imagick

Very importantly however, make sure you specify the path when prompted, to be /opt/local, do not let it auto detect! Once this is done it should compile successfully and you will be prompted to add imagick.so to your php.ini file.

PHP complains date.timezone is not set

Wednesday, November 28th, 2012 | Programming, Tech

Sometimes, PHP will kick up a fuss complaining about date.timezone not being set. We found this on the Symfony framework and were able to replicate it on standalone scripts.

[Exception]
DateTime::__construct(): It is not safe to rely on the system's timezone settings.
You are required to use the date.timezone setting or the date_default_timezone_set()
function. In case you used any of those methods and you are still getting this
warning, you most likely misspelled the timezone identifier.
We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead

Normally, you would fix this by editing your php.ini file and adding a declaration there.

date.timezone = "Europe/Berlin"

But we had already done this and it still wasn’t working! After some further investigation, it seemed that PHP simply couldn’t access the value.

echo(ini_get("date.timezone"));

This doesn’t make any sense, and we never got to the bottom of what was going on, but there are two ways around the problem. Firstly, you could modify your PHP script so that it makes a call to set the system timezone.

date_default_timezone_set("Europe/Berlin");

However, this involves having to modify your code, which is bad as you don’t want to have to set the timezone manually, especially in a piece of code which could be deployed to servers in different timezones.

A better approach is to set it in the vhosts directive in Apache.

php_value "date.timezone" "Europe/Berlin"

This isn’t the cleanest solution but allowed us to solve an otherwise unexplainable error.