Archive for the ‘PHP’ Category

Contributing to Open Source Software

Thursday, April 3rd, 2008

I’m a big fan of Open Source Software. Although I’m sure I could get by if I had to move to proprietary based software, at the present time, open source software earns me a living. Because of this, at the start of the year, I decided to give something back and start contributing to open source. I chose the Zend Framework, because it is written in PHP and is a project I have a lot of interest in. I registered for an account on the bug tracker and signed the CLA, but that’s as far as I got. I started looking through some of the bugs available for fixing, but found that the simpler ones were being dealt with quickly by other people and the only ones left where a little too complex for me. I still plan to contribute before the year is over. I intend to use the framework for a project I have in mind and the frameworks current implementation of a client for Amazon Web Services needs adding to for the purposes I need, so maybe I can contribute that way.

Back to the point, today I think I found a bug in PHPUnit, I couldn’t work out how to submit a bug report via the website, so I emailed Sebastian Bergmann with a patch. I’m not going to describe the bug until I know for sure that I’m correct, but I’m at least 90% sure I’m in the right. So, if I am right, that’s my first solid contribution to open source software.

Update

Well it seems I was right in reporting the bug, but it appears Sebastian didn’t like the patch I sent, or more likely it didn’t work. This changeset looks slightly different to the patch I submitted.

Index: PHPUnit/Util/Metrics/Function.php
===================================================================
--- PHPUnit/Util/Metrics/Function.php   (revision 2707)
+++ PHPUnit/Util/Metrics/Function.php   (working copy)
@@ -449,7 +449,7 @@
         }

         else {
-            $this->crap = pow($this->ccn, 2) * (pow(1 - $this->coverage/100, 3) + $this->ccn);
+            $this->crap = pow($this->ccn, 2) * pow(1 - $this->coverage/100, 3) + $this->ccn;
         }
     }

From what I can tell, the change put into place is also incorrect according to the C.R.A.P. index formula.

Update 2

I emailed Sebastian and he fixed it properly in changeset 2712

Popularity: 22% [?]

Linux/PHP one liner - Syntax check all files.

Tuesday, March 25th, 2008

Here’s a simple one liner you can use to syntax check all php files in your working directory.

find . -type f -name "*.php" -exec php -l {} \; | grep -v 'No syntax errors'

For those not familiar with the programs used, it basically reads as…. Find all files that end in ‘.php’ and with each of those files run php -l. This is then put through a pipe to the grep -v, which filters out all files that are syntactically correct.

Popularity: 18% [?]

10 tools for Modern PHP Development

Thursday, March 20th, 2008

A simple list of tools for modern PHP development. There are alternatives to most of the tools, but I’ll list native PHP tools wherever possible.

1. PHPUnit

PHPUnit is a testing framework belonging to the xUnit family of testing frameworks. Use it to write and run automated tests. Start using PHPUnit

2. Selenium RC

Selenium RC can be used in conjunction with PHPUnit to create and run automated tests within a web browser. It allows tests to be run on several modern browsers and is implemented in Java, making it available to different platforms. PHPUnit and Selenium

3. PHP CodeSniffer

PHP CodeSniffer is a PHP code tokenizer, that will analyse your code and report errors and warnings based on a set of Coding Standards. Documentation

4. Phing

Phing is a project build tool and is a PHP port of the popular Java program ant. Phing can be used to automate builds, database migration, deployment and configuration of code. Documentation. Database migrations with phing

5. Xdebug

Xdebug is a multi-purpose tool, providing remote debugging, stack traces, function traces, profiling and code coverage analysis. Debug clients are available in many PHP IDEs and even plugins so you can debug from everybody’s favourite editor vim. Documentation

6. PHPDocumentor

PHPDocumentor is an automated documentation tool, that allows you to write specifically formatted comments in your code, that can be brought together to created API documentation. Tutorial

7. phpUnderControl

phpUnderControl is a patch for the popular Continuous Integration tool, CruiseControl. Together with the previous six tools, phpUnderControl gives you a great overview of the current state of your application/codebase. Keep an eye out for Xinc

8. Zend Framework - or <insert your favourite framework here>

Frameworks facilitate the development of software, by allowing developers to focus on the business requirements of the software, rather than the repetitive and tedious elements of development, such as caching. There are plenty of frameworks to choose from, but I particularly like the Zend Framework. Have a read through this excellent Getting started guide

9. Subversion

Subversion is a revision control system that has superceded CVS. If you’re writing software of any kind, you shoud be using version control software.SVN Book

10. Jira

So I could have named one of many, but this is the one I’ve liked the most recently. Jira is a bug/issue tracking software package and can also help with project management in terms of goals and roadmaps. Most issue trackers link to version control repositories, such as Subversion. Only downside to Jira is that it costs for non open source projects.

I’m pleased to say that with a little bit of pushing and persuasion by myself, we are currently using all of these technologies with the exception of Jira, we have a bespoke issue tracker.

What do you think to the list? Anything I have missed? Any alternatives you prefer?

Popularity: 75% [?]

PHP Conference London 2007

Tuesday, January 23rd, 2007

A couple of days behind with this one, but I thought I’d post to help out. As alot of the PHP community have mentioned, The PHP London user group are running the UK’s second dedicated PHP conference on Friday, 23rd February. Confirmed speakers thus far are, Cal Evans, Simon Laws, Kevlin Henney and Rasmus Lerdorf.

I didn’t make it last year but will see what I can sort out this year.

Popularity: 24% [?]

Quick bandwidth optimisation tips for Apache and PHP

Monday, September 4th, 2006

Here’s a quick tip to optimise the HTTP response headers sent by your webserver. While being pretty useless to the average user, the Server signature and powered-by headers could be removed or at least reduced. Obviously these changes are only minor, but on a heavily loaded server such as large forums, could make a decent little saving.

These two little changes…

apache2.conf

ServerTokens Prod

php.ini

expose_php = Off

Will change the HTTP response headers on this server from:

Server: Apache/2.0.54 (Debian GNU/Linux) PHP/4.3.10-16 \
mod_ssl/2.0.54 OpenSSL/0.9.7e mod_perl/1.999.21 Perl/v5.8.4
X-Powered-By: PHP/4.3.10-16

To:

Server: Apache

That’s a saving of 128 bytes. This site has served 2025 requests so far this month, so this little trick might only have saved me 253kB, but what if there had been 20,000,000 requests?

payday loans cash advance needs

Popularity: 100% [?]

Brainbench PHP 5 Certification

Saturday, July 22nd, 2006

Intrigued by reading about the BrainBench PHP certifiation on Tobias Schlitt’s and Markus Wolff’s respective blogs (via PlanetPHP), I thought I’d give it a try.

To basically iterate what they both said, it’s bollocks. You’ve got three minutes to answer each question and as long as you’re quick with the online manual, most of the answers can be looked up easily. That said I didn’t get them all right, so I must have missed with a couple of guesses for one’s I couldn’t lookup. One in particluar was a function supposedly for verifying credit card numbers, the logic was too much for me to take in, not in three minutes anyway.

The code examples are filthy as well, the first one I got involved two ternary operators spread over two or three lines and similar to the Zend Certification, I think syntax highlighting would be nice on these things.

I do think being able to use the manual well is valuable skill, however. I have the PHP.net Manual set up as a quick search in Firefox, so an average search is simply a case of hitting ctrl-t (new tab), alt-d (focus to address bar), php function_name, enter. I do this all day long, I’m not bad at coding, but struggle to remember parameter order etc.

Here’s my results anyway.
Test Results

Popularity: 17% [?]

PHP5 objects assigned by reference?

Sunday, June 18th, 2006

I’ve been working with PHP5 since it’s release and find it very hard to believe I haven’t come across this yet. By default, in PHP5, assigning an object instance to another variable, the new variable will access the same instance, but not by reference? To quote the manual:

When assigning an already created instance of an object to a new variable, the new variable will access the same instance as the object that was assigned. This behaviour is the same when passing instances to a function. A new instance of an already created object can be made by cloning it.

Hence the code…

<?php

class MyClass
{
var
$myVariable = ‘1′;
}

$instance1 = new MyClass();
$assignNormally = $instance1;
$assignByReference = &$instance1;
$clone = clone($instance1);

$assignNormally->myVariable = ‘2′;
$clone->myVariable = ‘clone’;

var_dump($instance1); // 2
var_dump($assignNormally); // 2
var_dump($assignByReference); // 2
var_dump($clone); // clone

$instance1 = null;

var_dump($instance1); // NULL
var_dump($assignNormally); // 2
var_dump($assignByReference); // NULL
var_dump($clone); // clone

?>

Produces …

object(MyClass)#1 (1) {
["myVariable"]=>
string(1) “2″
}
object(MyClass)#1 (1) {
["myVariable"]=>
string(1) “2″
}
object(MyClass)#1 (1) {
["myVariable"]=>
string(1) “2″
}
object(MyClass)#2 (1) {
["myVariable"]=>
string(5) “clone”
}
NULL
object(MyClass)#1 (1) {
["myVariable"]=>
string(1) “2″
}
NULL
object(MyClass)#2 (1) {
["myVariable"]=>
string(5) “clone”
}
Had me puzzled at work for quite some time and I ended up searching the Bug reports.

Popularity: 22% [?]

Setting up an adserver

Saturday, May 13th, 2006

I recently set up an adserver, purely so I could split an ad spot on the proxy site between two campaigns, to see which one performs better.

Installing phpAdsNew, an open-source ad-server, was very easy and their documentation is excellent.

Creating the publishing zone was easy enough, then I had to create the two campaigns. The two ad networks I wanted to compare, were RightMedia and BannerConnect, which both use the yieldmanager software developed by RightMedia. I set these two up as Advertisers, then created a campaign for each. Then under the campaign you create a banner, which I created as HTML banners. Originally I used the standard yieldmanager tags, but this didn’t seem to work properly, I don’t think Internet Explorer was rendering the ads. Naturally I didn’t notice at first, I don’t do Internet Explorer. After changing to the Raw iFrame tags, I started getting plenty of impressions again and it worked out quite well.

I’m planning to move a few other ad zones over to the adserver, it makes sense and should help my acquire more money! Next step is to get the geo-targeting going, I’ve got nothing to geo-target right now, but should come in useful at some stage.

Popularity: 7% [?]

ZCE Diploma Arrives

Monday, April 3rd, 2006

Finally received my diploma from Zend today. I passed the exam way back in November last year and had emailed Zend twice asking politely, when I would be receiving it, but never heard back from them.

It appears to have taken the best part of nine weeks to get here, for some reason they’ve marked it ‘Surface Transportation Only.’

The diploma came in a little frame and I got a couple of stickers to go with it. Apparently I can claim some free ZCE business cards from some online company aswell.

Popularity: 2% [?]

Vim, CTAGS and PHP 5

Monday, March 13th, 2006

I’ve just discovered CTAGS, thanks to theTop 10 things Vi user need to know about Vim list.

Ctags generates an index (or tag) file of language objects found in source files that allows these items to be quickly and easily located by a text editor or other utility. A tag signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object).

To use CTAGS with PHP 5, I downloaded the CTAGS source code, and this patch. Bascially the patch adds capabilities for the private, protected and public visibilty keywords.

# wget http://kent.dl.sourceforge.net/sourceforge\
/ctags/ctags-5.5.4.tar.gz
# tar -zxvf ctags-5.5.4.tar.gz
# wget http://svn.bitflux.ch/repos/public/misc/ctags-php5.patch
# mv ctags-php5.patch ctags-5.5.4
# cd ctags-5.5.4

Now patch the php.c file

# patch php.c ctags-php5.patch

Configure build and install CTAGS

# ./configure
# make
# make install

CTAGS is now installed, we can start to use it. I’d recommend creating tag file for different projects seperately, rather than one big one in your home folder or something. So move to your folder of choice and create the tags file.

# cd /path/to/your/project
# ctags -R

This may take a while depending on how many files you have. Once it is done, you’re ready to start using CTAGS with Vim. The ‘-t’ option for Vim opens the file containing that tag. So..

# vim -t 'MyClass'

… would open the MyClass.php class definition file. Once inside a file, hitting ctrl-] while the cursor is over a function/class name, Vim will attempt to open the file with that tag. Pressing ctrl-t will take you back a step.

Popularity: 46% [?]