Posts Tagged ‘PHP’

Landing a PHP job Part 1: Technical Knowledge and Skills

Monday, September 8th, 2008

PHP Job Hunters Handbook

After reading this thread, I thought I’d spend some time writing about what I feel are some measures you can take to landing a job in PHP. This first part is going to concentrate on the kind of technical matters I think any PHP developer should at least have knowledge of, if not some kind of experience. A lot of the subjects discussed aren’t specific to PHP, but the focus will be on PHP. It’ll be far from exhaustive (please feel free to flame, but constructive comments would be nicer) and there’ll probably be quite a few references to Joel on Software articles, mainly because I’ve read a lot of them and I can’t be bothered to research the topics further! There’ll be plenty of links to follow, plus the odd dead tree format recommendation.


Programming

Code Complete 2

This should be a no brainer. Lots of experience of programming in PHP, is not strictly necessary, a good programmer, particularly with experience of scripting languages or programming for the web should be able to pick up PHP in no time.

For someone who is basically a good software developer, learning another programming language is just not going to be a big deal. In two weeks they’ll be pretty productive. In two years, you may need them to do something completely different in a programming language which hasn’t even been invented.

- Sorting Resumes by Joel Spolsky

Most PHP applications are used in conjunction with an SQL database, predominantly MySQL, so you’re going to need some of this under your belt.

Some knowledge of PHP is essential. Be aware of the benefits, the caveats and if you’re interested, a little of PHPs history, some people really care about it. I think it definitely shows you are passionate about what you do or want to do. Maybe look to PHP’s future, research whats coming up in PHP 5.3, or whatever the next version is at the current time.


Software Engineering

Most PHP roles go beyond just programming, so a good sense of what’s involved in a full project life cycle should help you get that PHP job over the next guy. There are lots of processes and models available, but you don’t need to be familiar with them all. Get a good idea of the 7 stages of the traditional Waterfall Model and you should be able to apply the principles to most methods. They are:

  1. Requirements Specification
  2. Design
  3. Implementation
  4. Integration
  5. Testing
  6. Installation
  7. Maintenance

I like UML for design and documentation, so worth knowing about even if you haven’t practiced it.

Libraries and Frameworks

If you are familiar with Object Oriented methodologies, arm yourself with the knowledge of PHP5’s OO capabilities. Once you’ve got that, get a handle of the vast array of PHP frameworks that are available. You don’t have to know them inside and out, just be aware of them and the benefits they give you. PEAR is a huge library of PHP code, check it out


Development Tools

There are plenty of tools available to aid and improve the development process, be familiar with as many as you can handle. I would insist on becoming familiar with, downloading and experimenting with subversion, or some other version control system.

Joel Spolsky has what he refers to The Joel Test. Later in this series, we’ll discuss interviews, and I will recommend asking at least one of these questions at an interview, so you need to understand what they all mean and why they might benefit a software development team.

Security


Essential PHP Security

Security is often a big cause for concern in the PHP world, mainly because it’s not been handled correctly before. PHP is not insecure in itself, most vulnerabilities attributed to PHP are actually simply in softwares written in PHP.

Be aware of security issues in your code such as SQL Injection, XSS and CSRF. Also be aware of configuration directives that can affect the security of your PHP powered web servers.


Web Services

Understand what a web service is and some of the related technologies. PHP is ideal as a glue language, combining web services to consume single web services or create mash ups of several web services, but can also be used for providing web services.

System Administration

In my opinion, developers should be capable of administering the full stack they develop for, usually in this case, the LAMP stack. There can’t be many potential PHP developers out there who don’t have a spare computer or hard disk lying around that they can’t install Debian on and follow a simple LAMP installation tutorial. If you’ve not got a spare hard disk, download VmWare Player and a debian appliance

I think thats all I can think of for now, I’m sure there’s plenty I’ve missed. If there’s any technical leads, managers or recruiters reading, please pipe up with what you expect from your applicants. The next part in the series will focus on the soft skills required for banking that PHP job.

More in this series

Zend PHP 5 Certified Engineer

Tuesday, July 15th, 2008

After putting the exam off continuously for about 18 months, I actually got around to taking my Zend PHP 5 Certification exam. I originally scheduled the exam, put it off for a few months, then actually forgot about the exam altogether, only to reminded by google calendar an hour before I was due to take it. The test centre was at least an hour away, so that was a waste of $125. I scheduled the exam again, kept putting it off until I caved in last month and got it done.

The exam itself was considerably harder than the original, I wasn’t all that confident when I clicked the ‘End Exam’ button, but I got the job done. I’m glad I found it harder, I’ve obviously improved my knowledge of PHP since I took the original exam nearly 3 years, so they must have made the certification more difficult to achieve.

As far preparation goes, I read the study guide right through once, making notes along the way. I turned up at the test centre about 20 minutes early and went through my notes. The study guide clearly did a good job!


Zend Certified Engineer

Processing output with SimpleXML

Tuesday, July 8th, 2008

PHP’s output buffering allows you to register callbacks, that will process the output before returning it back up the stack. This feature is usually used in conjunction with handlers added by PHP or it’s extensions such as ob_gzhandler, which gzips the output, or ob_tidyhandler, which passes the output through tidy. As output buffers can be stacked, you can use many handlers in turn using the ob_start function.

<?php 

ob_start('ob_gzhandler');
ob_start('ob_tidyhandler');

?>

Because you can pass ob_start any function name you desire, adding custom handlers is easy. At my current workplace, we needed a quick fix for something we’d overlooked and because we’d (fairly) strictly stuck to generate decent markup, we used an output handler in combination with SimpleXml to manipulate the DOM in our HTML pages. I can’t divulge the what we needed to do or the details of how we did it, but here’s a basic example that will attempt to insert a CSS link to a page.

<?php
function process_output($buffer)
{
    try {
        $xml = new SimpleXmlElement($buffer);
        if (isset($xml->head)) {
            $link = $xml->head->addChild('link');
            $link->addAttribute('rel', 'stylesheet');
            $link->addAttribute('href', 'http://o.aolcdn.com/dojo/1.0/dojo/resources/dojo.css');
            $link->addAttribute('type', 'text/css');
        }
        return $xml->asXML();
    } catch(Exception $e) {
        error_log($e->getMessage());
        return false;
    }
}

ob_start('process_output');

?>

This code can be added to a file that’s included in every page for a quick fix, but beware of performance hits. A quick test showed adding the above processing dropped this example files performance from 960 requests per second to 795 requests per second.





Fat Models and the Data Access Layer

Tuesday, June 17th, 2008

There’s been some discussion recently on why active record:

  1. Sucks
  2. Sucks – but not like that;
  3. Doesn’t suck

I like the active record pattern, so I don’t think it sucks, but I do think it’s used a little out of context sometimes.

If you’re building a small lightweight app, then I think using your Data access layer as the M in MVC is a logical thing to do. It’s quick, it’s easy and you can extend either your active record in Rails, or extend your Table DataGateway in the Zend Framework and you wont go far wrong.

As soon as your app gets a little more complex, you might want to start creating custom
models that contain more business logic than simply pulling and pushing to the database. If your application is complex enough, chances are your model will need to interact with more than one database table, if not database, so at this point, like Bill Karwin pointed out, your model should be using the DAL, not being the DAL. Loosening the coupling between model and DAL, should also help with automated testing the business logic, in that mock objects could replace the DAL.

The only problem is, I don’t know the best way to do it.

I’m currently learning the ways of the Zend Framework and would be interested to see how people think the best way to implement this kind of complex model. I’m currently leaning toward something like this. I’ve included a Zend_Form object, to show how the Persons model encapsulates more logic than just pushing to and from the database. I think the biggest benefit of Zend_Form is validating input, which I consider domain logic, so should be part of the model. But I’m not sure the best way to make things easily testable, without pushing into the realms of fancy Dependency Injection and what not, which I’m not all that familiar with.

File: application/models/Persons.php

<?php

class Persons
{
    public function findByEmail($email)
    {
        $table  = self::getTable();
        $select = $table->select()
                        ->where('email = ?', $email);
        return $table->fetchAll($select);
    }

    public static function getTable()
    {
        // add some dependency injection?
        return new Persons_Table();
    }   

    public static function getForm()
    {
        // add some dependency injection?
        return new Persons_Form();
    }

    // ...
}

File: application/models/Persons/Table.php

<?php

class Persons_Table extends Zend_Db_Table
{
    protected $_name = 'persons';

    // ...
}

File: application/models/Persons/Form.php

<?php

class Persons_Form extends Zend_Form
{
    // ...
}

At first it may seem that the Persons model just ends up acting as a proxy to the Persons_Form and Persons_Table, but once you start writing methods that use both together, you’ll start seeing fatter models and thin controllers, which is all good.

This really is a request for comments really, as I’m personally not sure about the best way to go about this. Would be interesting if any of the people using the MVC part of the Zend Framework in the real world go about this?

Software development podcasts

Tuesday, June 3rd, 2008

I recently picked myself up an 8GB Ipod Nano, I spend a fair bit of time walking my little dog Murphy and I’ve found it great for both music and more recently podcasts. So much so, that I quickly got few to the few podcasts I was subscribed to, so went in search of more. I’ve listened to and liked very much:

  • PHP Podcasts rss
  • Stack Overflow rss

The new editions to my list are:

  • Audible Ajax rss
  • Code Sermon rss
  • Google Developer Podcast rss
  • WebDevRadio rss
  • The Web 2.0 Show rss

I’ll pipe back in a couple of weeks and give my thoughts on the new ones.