Posts Tagged ‘PHP’

Wing Commander using Composer

Wednesday, November 14th, 2012 | Programming

Back in July, I wrote about Wing Commander, a little library I had written to draw together the very awesome Flight PHP framework and Mustache.php template library.

Times have changed though and everyone is using Composer now (you are using Composer, right? 😉 ), not to mention that even at the time, Wing Commander was using a slightly dated version of the Mustache library. So I decided it was time for an update.

Said update was then completed in a lunch break (and a bit of an evening too) and is now available, and listed on Packagist, which means you can easily install it via Composer.

{
	"require": {
		"xmeltrut/wing-commander": "dev-master"
	}
}

That is all you need in your Composer configuration file, and it will install Flight, Wing Commander and Mustache – plus, it’s now even easier to use than it was before. Full information can be found in the readme.

PHPUnit on OSX Lion CLI

Saturday, November 10th, 2012 | Programming, Tech

If you’re trying to run PHPUnit from the terminal in Mac OSX Lion, you may get an error similar to the following.

File/Iterator/Autoload.php failed to open stream

You can resolve this by running the following commands.

curl http://pear.php.net/go-pear.phar > go-pear.php
sudo php -q go-pear.php

PHPUnit should now run without errors (or at least, without errors in their code 😉 ).

PHPNW12

Thursday, October 18th, 2012 | Events, Life, Programming

As part of my push to attend more conferences this year, and get out into the real world, I recently attended PHPNW12, a PHP developer conference that took place in Manchester.

I arrived on the Friday night and checked into the hotel across the road from the conference, the Britannia. With it’s sweeping balconied staircases it felt like I was in a 70s horror movie. The floors creaked and the light in the corridor outside my room flickered on and off constantly – indeed, it rather ruined the mood when they fixed it.

The Friday night featured a hackathon, though not feeling too well due to the tail end of a cold, I spent about 20 minutes hacking, then ate my pizza while I checked my emails for an hour and headed to bed, not to emerge until 12 noon the next day when I felt a bit better.

The talks were on the whole good – there was a real range in there, some had really interesting topics but due to their lack of experience presenting talks, where rather dull. Others were confident and entertaining speakers who despite presenting quite dull topics (caching is not going to be mega interesting) presented brilliant talks. On balance, I would certainly prefer them to focus more on speaker quality over topics next year.

On the Saturday night there was a social including dinner, at which I spent quite a bit of time getting to know some of the other people at Sky – I didn’t realise they were going as I hadn’t gone with Sky, but it was great to see some familiar faces there.

Overall, I found I learned a lot from it. If I can bring back just a few ideas to my own business then it will have been worth the expense.

Staircases in the hotel. I also tried the new panorama function on iOS6, on it’s side:

Installing Postgres PDO driver on cPanel

Friday, October 5th, 2012 | Life, Tech

cPanel offers two options for installing PDO – using EasyApache which can enable PDO and MySQL’s PDO driver or installing everything via PECL. Unfortunately, under PHP 5.3, the PECL installers don’t work, so if you need any other PDO drivers, you’re in a hole.

Luckily, you can install it manually.

Download the PDO driver from the PECL website. Extract the archive and CD into the directory.

wget http://pecl.php.net/get/PDO_PGSQL
tar -xzf PDO-PGSQL-1.0.2.tgz
cd PDO-PSQL-1.0.2/

Once this is done, run the standard commands for building a PHP extension.

phpize
./configure
make
make install

Once this is done, you can add the extension to php.ini.

cd /usr/local/lib/
vim php.ini
extension=pdo_pgsql.so

Finally, restart Apache and the Postgres driver should show up in your phpinfo() output.

Installing Mongo PHP driver on CentOS 6 cPanel

Monday, September 17th, 2012 | Life, Tech

Once again, the PECL installer. In order to get the Mongo driver for PHP working, you need to install it manually.

mkdir mongo
cd mongo
wget https://github.com/mongodb/mongo-php-driver/zipball/master
unzip master
cd mongodb-mongo-php-driver-df8b217
phpize
./configure
make install

Add the extension to your php.ini file.

extension=mongo.so

Restart Apache, and Mongo should appear inf your phpinfo() output.

Installing APC for PHP on Fedora 15

Sunday, August 12th, 2012 | Life, Tech

This is how to install APC for PHP on Fedora 15.

yum install php-devel
yum install pcre-devel
yum install php-pear
pecl install apc

Create a file in /etc/php.d named apc.ini, containing the following.

extension=apc.so

PHPUnit and PEAR packages break on Mountain Lion

Monday, August 6th, 2012 | Programming, Tech

If you have recently upgraded to Mac OS X Mountain Lion (10.8) you may find that PHPUnit and other PEAR packages no longer work. You may get errors similar to the following.

PHP Copy & Paste Detector

Warning: require(PHPCPD/Autoload.php): failed to open stream: No such file or directory in /Users/chris/pear/bin/phpcpd on line 49

Fatal error: require(): Failed opening required 'PHPCPD/Autoload.php' (include_path='.:') in /Users/chris/pear/bin/phpcpd on line 49

PHP Mess Detector

Warning: require_once(PHP/PMD/TextUI/Command.php): failed to open stream: No such file or directory in /Users/chris/pear/bin/phpmd on line 38

Fatal error: require_once(): Failed opening required 'PHP/PMD/TextUI/Command.php' (include_path='.:') in /Users/chris/pear/bin/phpmd on line 38

Unfortunately, there doesn’t seem to be an easy way to fix them, other then by reinstalling each package.

sudo pear install --force --alldeps phpunit/phpunit
sudo pear install --force --alldeps phpmd/PHP_PMD

The tools should then run as expected.

Install APD on CentOS 5

Thursday, July 19th, 2012 | Life, Tech

Here is how to install APD (Advanced PHP Debugger) on CentOS 5. Lets start by creating a directory for it to log files to.

cd /tmp
mkdir apd
chown apache:apache apd

We need to remove ioncube, or it will cause errors.

rpm -e php-ioncube-loader

Now we can install APD, via PECL.

pecl install apd

Add the following to php.ini.

[apd]
zend_extension=/usr/lib64/php/modules/apd.so
apd.dumpdir=/tmp/apd
apd.statement_tracing=0

My PHP binary was in a different location, so I had to alter the script too.

cd /usr/bin/
vim pprofp

Change /usr/local/bin to /usr/bin and save the file.

You also need to ensure PEAR is in your include path (/usr/share/pear) for the script to work.

Lithium

Tuesday, July 17th, 2012 | Programming

Recently, I’ve been re-developing Authority Forums and as part of the re-development, the site has been re-built from the ground up, using the Lithium framework.

Lithium, which bills itself as “the most RAD framework for PHP” is a spin-off from CakePHP. I’ve used the CakePHP framework for previous projects, and it’s an OK framework, but I didn’t find it to be something special. Neither did some of the core developers apparently, who left to start Lithium. It’s also contributed to by Richard McIntyre, who gave the talk on The Future of PHP that I blogged about last month.

It is an easy framework to get started with. I say that; it took me twenty minutes to work out that I needed to download both the Lithium and framework packages to get started. But once I had stopped missing the obvious, everything was up and running very smoothly.

In particular, creating models was very easy. All you do is create a class with the name of your database table and have it extend the Lithium base model. That’s it! You don’t have to tell Lithium what the content of the table is, it figures all of that out by itself and gets you up and running with a CRUD-supporting model immediately.

Of course, this isn’t always ideal for performance and security reasons, but you have significant customisation options that you can dig into to tweak things as you need them. Or, if Lithium just isn’t doing the trick to you, you can easily replace it with Doctrine, or any other ORM of your choice.

It also comes with a good range of built-in libraries. Perhaps not quite as comprehensive as Symfony2, but certainly easy to get started to and that just turn on and off as you wish – most are off by default but can be turned on my uncommenting a few lines. It also has ground-up support for MongoDB.

Deploying was easy too. Lithium automatically figures out whether the current install is dev, test or production and adjusts everything appropriately, so all you do is enter the connection details for databases on each environment and Lithium intelligently figures out which ones to use without you having to tell it, removing the need for slightly different code or a non-writable configuration file.

That said, deployment wasn’t quite as smooth as it could have been, and resulted in a bit of last minute panic. Lithium’s major weakness right now is the lack of community support and documentation. The documentation they provide is fairly good, but unless you’re doing exactly what the example is showing you will run into problems.

I would say I spent more time digging around the API documentation than I did the manual. This isn’t the case with Symfony2 (though I’m not a fan of the Symfony2 documentation either), so if you’re not comfortable doing this, it’s a tough framework to work with. More importantly, though, there just doesn’t seem to be other users doing real-world stuff, and so on several occasions, I had to find myself guessing at how to use functionality.

A good example of this is how to filter a query based on a range. It is easy to do a “I need this column to equal this” for example, but what happens when you want to do “I need this column to be greater than this.” In the end I guessed you could supply a sub-array with the value and the operator – and it turns out you can! But I couldn’t find any documentation for this, even though the functionality clearly is there. What they really need is a user forum (and users! It could just be on Stack Overflow like every other piece of knowledge you ever need).

Overall, I’m really enjoying using the Lithium framework. Its lack of user community is a massive drawback, but wider adoption will solve that and it should be more widely adopted because it’s a great framework.

Install memcached on CentOS 5

Friday, July 13th, 2012 | Life, Tech

First step, you’ll need to add the EPEL repository to Yum.

Once you’ve done that, you can install all the YUM packages.

yum -y install memcached.x86_64 libmemcache.x86_64 libmemcache-devel.x86_64 zlib-devel.x86_64

Then add the memcache extension to PHP.

pecl install memcache

Add the extension to your PHP configuration.

extension=memcache.so

Configure memcached appropriately.

vi /etc/sysconfig/memcached
add OPTIONS="-l 127.0.0.1"

Configure it as a service, and start.

chkconfig memcached on
service memcached start