Learn More About PHP And The Web Platform!

Struggling with your web server, or to scale your PHP application to meet growing demand?

Whether you're running one server or a whole server farm; whether you're hosting on Windows Server or on Linux.

Learn from Stuart's experience with system design, delivery, support and management to help you do a better job and have an easier time.

Beneath Whitby breakwater

I haven’t really talked much about my upcoming tutorial session at #phpnw12 next month before now, but I hope there’s still time to convince you to come along and learn how to use Git as your team grows in size.

That’s what I’m teaching: a strategy, plus supporting tools for Git called HubFlow, that will help you stay sane – and more importantly help you keep delivering – as your team starts to collaborate on your product.

It isn’t my strategy: the credit must go to Vincent Driessen, who first blogged about GitFlow at the start of 2010. And they aren’t my tools: again, they originally come from Vincent. All I’ve done is adapt them for working against GitHub – hence the name “HubFlow”; but if BitBucket is more to your taste (or wallet) then rest assured that both tools and strategy work can be adapted for there too.

Maybe you don’t need this strategy. If you’re working on one-off consulting gigs for clients, where you can get in quick and get out quick, then HubFlow might not be necessary. But if you’re working on any sort of product or service, either commercially or open-source, then I can strongly recommend HubFlow to you – even if you’re just at the one-man startup stage. And the benefits of adopting HubFlow only increase as your team grows in size.

I’ve already put a lot of effort into documenting HubFlow, and if you’ve previously read the docs, you might be feeling confident enough to adopt it by yourself. If you do, I think that’s awesome, and you should go for it without delay. Please do email me if I can help in any way. I’m passionate about everyone adopting the fundamentals of software engineering, and few things are more fundamental than good source control.

But if you’re still reading at this point, I hope that I can convince you to buy one of the remaining tickets for my tutorial session at #phpnw12. I don’t personally profit by it – all of us teaching at #phpnw12 are volunteers – but maybe you will.

What I’m teaching is the approach that I’ve introduced to DataSift. You might not have heard of us yet; we provide a platform for filtering social data in real time, handling terabytes of data a day at full firehose-scale, and many thousands of incoming data every second. And every piece of that data goes through code written in PHP.

Although we’re a young startup, we’ve already grown beyond 20 developers, and with that many people collaborating to build that platform, with every team working at their own pace, we needed to adopt a common way of working together with Git and GitHub so that the company continued to scale well.

  • It had to be a way that allowed every developer to take full advantage of Git, especially when it comes to committing their work early and often.
  • It had to allow developers to form ad-hoc teams that worked at their own pace.
  • Remote working is a fact of life these days, and it had to work just as well whether everyone is in the office or working from somewhere else.
  • It also had to ensure that only work that had been finished made its way into any of our releases.
  • We wanted to make sure that there was an opportunity to review every change before it went into a release. Code reviews play an important part in delivering high-quality work time after time after time.
  • We didn’t want pending releases to hold up new development, ever.
  • And if something did screw up in production, we needed a way to go back to our last known good version, fix it, and release *that* – all without disrupting any pending releases or existing ad-hoc teams.
  • Finally, it had to be easy to teach to people who are new to Git and GitHub, preferably by wrapping complicated Git operations up inside a single command each time.

Those are the benefits that HubFlow gives us. And at #phpnw12, I’ll be teaching everyone who attends my tutorial session how to get those benefits too.

What makes me qualified to teach this topic? And what makes me qualified to be teaching at all?

I’ve got 18 years of experience setting up and/or running software configuration management, taking in systems as diverse as RCS, CVS, Perforce, Continuus, Clearcase, Subversion, Mercurial, and Git. I’ve done this with, and for, organisations as small as a one-man team all the way through to large international corporates. I’ve even built a version control system for one company in the past. (Git is much better! 🙂 And I was around long enough to see (and learn from) the failures as well as the successes. (I’m a big believer that success teaches you a bit, but failure teaches you more). Plus, I’m the author of the HubFlow strategy, and the maintainer of the HubFlow extension for Git.

It simply isn’t possible for me to distill all of that rich and lengthy experience down into the documentation that I’ve written for HubFlow. I think the documentation is good – I wouldn’t have put my name to it otherwise – but I think you can learn even more from me in person.

I’m a qualified teacher of adults. I’m trained how to teach, and I’ve had a lot of practice doing so. My first PHP conference appearance was back in 2004 on Marco’s php|cruise, and since then I’ve spoken at the PHP NorthWest and PHP UK conferences several times. I co-wrote the Zend Certification Study Guide for PHP4. Once a year, I teach at the University of Aberystwyth, helping their Comp Sci students prepare for applying for jobs for their year in industry. Plus I’ve done a substantial amount of teaching and mentoring as part of my job and open-source work over many years. And away from computers, I’ve been teaching martial arts for over 12 years.

If you need the benefits that HubFlow brings, then I’d love to teach you in person. You can buy a ticket for my tutorial day on the #phpnw12 website. I hope to see you there.

Be the first to leave a comment »

If you’re using Sublime Text 2 w/ my PHPUnit plugin, but you have phpunit installed into a non-standard place (i.e., it isn’t installed into your system path), then keep reading – this change is for you.

You can now tell the PHPUnit plugin where to find phpunit, by adding the following to your PHPUnit.sublime-settings file:

{
    "path_to_phpunit": "/Users/stuart/build/pear/phpunit"
}
3 comments »

I don’t need the ticket that I bought for the PHP NorthWest 2012 conference, as I’m doing one of the tutorial sessions on the Friday. So I’m going to be giving my ticket away to one lucky reader. The ticket is for both the Saturday and the Sunday sessions, and if memory serves covers all the socials too. You’ll have to pay for your own transport and hotels tho, so please don’t enter unless you’re definitely able to travel to the conference if you win.

To win my ticket, leave an interesting PHP or software development-related question in the comments below. The winner will be the question that I think would be the most interesting to answer, and I’ll answer it for you over either lunch or dinner at the PHPNW12 conference. You must leave your comment by 9am BST on Monday 10th September, and I’ll announce the winner on my blog later that day.

So get asking away 🙂

(Please note: comments on my blog are moderated, so if you leave a comment and it doesn’t show up straight away, that’s why).

UPDATE: we have a winner, who I’m currently trying to get in touch with

1 comment »

Tweaking BrowserMob-Proxy

Posted by Stuart Herbert on August 10th, 2012 in Toolbox.

If you’re writing tests for your web-based applications (and if you’re not, I’m sure Chris Hartjes will want a stern word with you …), then you might be using a combination of Selenium 2 / aka Selenium WebDriver and WebMetrics’ BrowserMob-Proxy for your testing.

WebDriver is the latest Selenium API for controlling real web browsers such as Internet Explorer, Firefox and Chrome, and BrowserMob-Proxy adds in essential missing capabilities such as checking HTTP status codes and injecting headers for HTTP Basic Auth.

I’ve recently forked BrowserMob-Proxy on GitHub and started to make tweaks to it for work. Thought I’d mention it, in case anyone else out there is using BrowserMob-Proxy and would find our tweaks useful too. We’ll be submitting our tweaks upstream in due course.

  • Executable JAR – Maven POM file updated to build browsermob-proxy-X.XX-standalone.jar – an executable JAR file – during the ‘package’ phase. Very handy if you’re running and testing it via the remote API. Upstream’s browsermob-proxy-X.XX-bin.zip is still available, and is now always built during the ‘install’ phase.
  • /features endpoint – a new REST API endpoint allowing you to GET and POST and DELETE feature flag settings. We’re using this to enable/disable any new features that might break backwards compatibility, in case you want to use existing BrowserMob-Proxy REST clients with our tweaked version. Said REST clients can also use this to see which features are present / enabled.
  • enhancedReplies – by default, BrowserMob-Proxy isn’t the most chatty of REST services. Switch this feature on (POST ‘enhancedReplies=true’ to /config/enhancedReplies), and now every response includes either a ‘success: TRUE’ or an ‘error: TRUE’ field for your client to easily understand what has happened.
  • More logging – we’ve added some additional log messages throughout the ProxyResource REST API, to make it easier to debug browsermob-proxy REST API clients. This logging is off by default, and is switched on by POSTing ‘paramLogs=true’ to /config/paramLogs, and/or POSTING ‘actionLogs=true’ to /config/actionLogs.
  • additional header GET / DELETE API – we’ve extended the REST API for additional HTTP request headers to now allow you to GET /proxy/:port/header/:name and to DELETE /proxy/:port/header/:name if you need to. You can also delete all additional HTTP request headers in one go by DELETE /proxy/:port/headers.
  • REST API for HTTP Basic Auth – BrowserMob-Proxy’s existing support for HTTP Basic Auth is now available via PUT /proxy/:port/basicAuth/:domain. One of the key features missing from WebDriver. (This is a convenience feature; it could be done by injecting the headers directly into BrowserMob-Proxy).
  • exception handling – by default, BrowserMob-Proxy lets exceptions bubble up to the servlet container … which unfortunately sends back HTML errors rather than a JSON error. To make things a little easier for REST clients, I’ve tweaked the REST API to trap exceptions and return back a (hopefully suitable) error class. This will probably need more tweaking before it provides useful information all the time.

Bookmark this page; I’ll be updating it as we complete more tweaks to BrowserMob-Proxy.

1 comment »

Taken at the Google Campus in London last night:

Right now, everyone is hiring. It’s nuts. In 18 years of being a professional software engineer, I’ve never known a time like it. We’ve gone from a society where it was considered a bit odd to be interested in computers, to a world where software engineering skills are the single-most in demand skill today.

This is what you’re competing against – and this is before Facebook and Microsoft open up their new London offices. So the question is … if you’re someone trying to hire developers for your firm, what are you going to do in the face of this competition?

6 comments »

Aim Higher!

Posted by Stuart Herbert on July 26th, 2012 in Opinion, PHP In Business.

At the start of the month, I was on a panel at Unified Diff (which, if you’re in the South Wales area, is well worth your time going to every month), and the last question we had is well worth expanding into a blog post. We were asked what each of us would do with a failing developer, and everyone was taken aback by my unequivocal answer: I’d fire them. After some back and forth between us (which carried on over a pint afterwards), my fellow panelists concluded that I seemed to be able to afford higher standards than they could in their organisations.

And that comment really struck a chord with me.

Fire Failing Developers

So why would I fire the failing developer? By keeping that person on you’re damaging the morale of the rest of the team, and you could end up losing good people and being stuck with the one you should have fired in the first place. (Guess who learned this one the hard way!) You’re also wasting your firm’s money on the person, you’re probably damaging your product, and if the person has any direct contact with your customers, you’re probably damaging your firm’s reputation there too.

Can you turn a failing developer into a star developer? Perhaps, and you should definitely try to do so. In fact, that’s part of your job – to spend every single day trying to turn every developer you manage into a star in their own right. Never wait for someone to start to fail. If you’re doing your job right, then when someone reaches the point where they’ve become a failing developer, you’ve already done all you can about it.

I’ve had to do it a few times over the years, and it feels bloody horrible every time. It’s not a nice thing to have to do, whether it’s an employee or a supplier. I always want to see the best in someone, and I always want them to have the success they deserve. But it’s part of the job, and you do no-one any favours by not facing up to it if it has to be done.

Why Do You Aim So Low?

What about higher standards? How come I seem to be able to afford them when others feel they cannot?

When I was a kid, I sat a lot of exams throughout my school years, but I was never remotely interested in how well I’d done versus everyone else. What I cared about was measuring myself against what was possible. How high could I consistently score? What was the next level up of test that I could sit? What could I learn from other sources? How could I apply it, play with it, really get inside it to start to actually understand it a bit? Where did the hard work need to be put it to take it further still? How could I have fun with it?

I’ve applied this approach to everything I do, whether it’s software engineering, writing, speaking, music, photography, or my martial arts. And I have found it to be liberating. My constraints are my slow-witted mind, my somewhat broken body, and the march of time … and I am in competition not with you, and not with failure, but only myself.

In a world of frankly very low standards, if all you do is measure yourself against the people around you, then it really doesn’t take much to seem like you’re doing pretty well. There are a lot of advantages to being ahead, it’s true, and evolution does favour the lazy … but you’ll never amount to anything much, and you’ll never achieve anything worth a damn if you don’t lift your gaze, look out to the stars, and see what can really be done.

This world is full of people with amazing potential, who never realise that potential. They’re just a waste of space. You can be better tomorrow than you are today. Aim high. You can do it. Everyone can do it. You just have to choose.

We don’t have a lot of time to achieve things in life, and as you get older, you become more and more aware of just how quickly the days are passing. Every day you spend just trying to get through the day … you can’t get that day back. It’s gone forever. And you never know when fate is going to cut your days suddenly short. Make the most of them. Achieve something worth while, and aim high when you do.

7 comments »

At work, we’ve recently published HubFlow: instructions + tools for using Vincent Dreissen’s GitFlow model with GitHub.

The full article is over on the DataSift dev blog.

2 comments »

I’ve recently built a product in Node JS, and it was a very positive experience (more on that in another blog post). I’m now looking around at what I need to do to package it all up for customers and entrepreneurs – hosting, developer meetups, that sort of thing. I’m looking for the wider ecosystem that customers can tap into. I’m a bit surprised at what I found during my research, and I thought I’d share it in case anyone else can add to it.

Why Hosting Matters

Let’s not beat about the bush here. As a rule, Node JS’s target audience probably doesn’t know enough to safely and securely run their own Internet-connected servers. It isn’t their skillset. A customer using Node JS really needs someone to look after all of that for them.

That isn’t a service I want to have to build myself if I don’t have to. For the customers I’m targeting, being able to say, “go there, sign up, and deploy to their cloud, and they’ll look after it all for you” is the right solution for everyone.

Where Is All The Hosting?

With all the buzz and hype around Node JS, it seems reasonable to think that there’d be plenty of cloud providers out there offering Node JS hosting services. Not the “here’s how to install it into a VPS”-type stuff, but a Heroku / Engine Yard-like service targeted at Node JS.

However, a quick Google for “nodejs hosting” turned up the following results on the front page:

  • 1 hosting provider which is public, free, and unable to provision new services when I tried (No.de)
  • 3 hosting services in private beta (Nodester, NodeSocket, and NodeJitsu.
  • … and zero paid-for ads offering Node JS hosting.

No.de is the hosting service from Joyent, who are the current guardians of the Node JS project itself. Their Node JS product page directs you to the No.de service. But unfortunately, No.de is a limited-capacity service, and you can only get your app on there if you’re lucky enough to catch them when there is spare capacity. Joyent do offer a VPS w/ Node JS pre-installed, but you’d be hard-pressed to find the product if you didn’t know it existed, as it isn’t linked to from their Node JS page at all.

The other three services all look interesting (NodeJitsu in particular caught my eye), but I can’t sit down in a sales meeting today and recommend any of them to a customer, because until they are public services, I can’t be sure that my customers can get a login and get their apps deployed and running.

But what really caught my eye is that no-one seems to be using Google AdWords to advertise their Node JS hosting service right now. That’s a significant smell, and a big surprise to me. I don’t want to draw any conclusions about that, just simply ask the question: does it mean that there’s an opportunity that isn’t being exploited yet, or does it mean that the opportunity isn’t big enough yet for folks to invest in?

Where Are The Community Meet-ups?

As well as hosting, I’m also interested in being able to introduce customers to other Node JS users, preferably through established developer meetup groups. From the customer’s perspective, being part of a community helps them broaden their skills and experience, and potentially helps them find new employees if they start to grow. From my perspective, the most valuable marketing of all is word of mouth, and having customers going to meetups and saying that they’re using our product because it solves their problems is a very important way of finding new customers.

We’re just outside London, which is a veritable hive of startup activity these days. But looking on Meetup.com for existing meetups for Node JS, all I could find is this waiting list. I did find the London Node User Group via Lanyrd, and I plan on trundling over to their next meetup on Wednesday, but that was it.

We seem to have meetups coming out of our ears in London right now on all sorts of technical topics; the lack of ones focused on Node really does stand out.

Thoughts And Conclusions

For a product that has had a lot of sustained buzz, and which is a good solution for some technical problems, the almost complete absence of an ecosystem around Node JS caught me completely by surprise. Are we just ahead of the curve, and using Node JS very early on in its adoption? Are there resources out there that I’ve just failed to find? Or is Node JS actually just another passing trend which failed to get enough traction?

I don’t know. Your thoughts and comments most welcome below!

42 comments »

So that I don’t forget how to do this next time around. Worked for me, your mileage may vary.

First step is to get a working install of PHP.

  1. Download PHP 5.4.latest ZIP file from the PHP Windows website
  2. Unpack the ZIP file into c:php. You should end up with c:phpphp.exe
  3. Copy c:phpphp.ini-development to be c:phpphp.ini
  4. Edit c:phpphp.ini to suit (e.g. set date.timezone)
  5. Make sure you add c:php to your system PATH (via Computer’s Advanced Properties -> Environment Variables)
  6. Reboot (this is Windows, after all 🙂

At this point, you should be able to open up a Command Prompt, and type ‘php -v’, and see the response ‘PHP v5.4.latest …’ appear as expected.

Now for PEAR itself.

  1. Open http://pear.php.net/go-pear.phar in a browser, save this file into c:php
  2. In a Command Prompt, cd to c:php and then run “php c:phpgo-pear.phar”
  3. At the prompt, select ‘system’. A text menu of paths will appear
  4. Fix the default path for pear.ini (option 11) to be c:phppear.ini
  5. Fix the default folder to look inside for php.exe to be c:php
  6. Make sure the binaries folder (option 4) is c:php
  7. Check all of the other options, make sure they are prefixed with c:php
  8. Press ENTER, and you should see PEAR downloading various PEAR packages onto your system
  9. Double-click the PEAR_ENV.reg file in c:php
  10. Reboot again to make sure PEAR_ENV registry entries have taken effect

At this point, PEAR is installed and should be available to use in your own projects, or with something like Phix.

Personal Notes

Some reminders to myself for the next time I have to do this.

  • Documentation for PHP for Windows and PEAR for Windows both seem to be out of step with current downloads. There’s currently no Windows installer for PHP available, and the PHP .ZIP file doesn’t contain the ‘go-pear.bat’ file.
  • You have to pay close attention to the default folders offered when running ‘go-pear.phar’. They appear to use the current working directory as the prefix even when installing system-wide, except for the location of pear.ini and php.exe – neither of these defaults are sane, and must be manually changed during the install 🙁
  • After install, pear command doesn’t seem to be 100% compatible with its behaviour on Linux and OS X. -D switch didn’t work, there may be other problems too that I haven’t yet found.
  • Both reboots are required – I’m not taking the piss there – for all running Windows apps to pick up the changes.
19 comments »

Wow. Last week’s opinion piece about switching from Netbeans to Sublime Text 2 has been the most popular blog post I’ve written for quite a while.

As the interest seems to be there, I thought it would be a great idea to follow up with a post taking you step by step through how I’ve set up Sublime Text 2 for PHP development, and showing you some of the useful features that you get out of the box with Sublime Text 2.

You’ll find the details below, and as a bit of an experiment, I’ve also put the details together in a series of YouTube videos for those folks who’d prefer to see ST2 in action. The video directly below is the first in the playlist, and I’ve also put the video for each feature separately further down. If you like the videos, please do click the ‘Like’ button on YouTube so that I know 🙂

Tip: If you can’t see any YouTube videos on this page, you might need to switch off your browser’s AdBlock plugin and then reload the page.

Install Package Control, Soda, And A Syntax Highlighting Scheme

Out of the box, Sublime Text 2 is a very good text editor. It’s so good, in fact, that I’ve seen people use it in its vanilla form perfectly happily for days and weeks before realising that it can be enhanced with third-party plugins!

The first plugin I recommend installing is Will Bond’s Package Control (installation instructions). Package Control is a plugin that automates the job of installing and upgrading plugins. After you’ve installed it, restart ST2, and then you’ll find a new “Package Control” menu option at the bottom of the “Preferences” menu.

There are over 200 community plugins currently available for ST2. You’ll find them by going into Package Control and selecting the ‘Discover Packages’ option. This takes you to the community packages webpage, where you can browse or search through the available packages. It’s worth going back and checking this page from time to time, as new packages are being added on a regular basis.

The next thing I normally do is reskin ST2. This is entirely a personal preference! Using Package Control, install the ‘Soda’ Theme plugin; this downloads the plugin, but does not activate it. Then, open up the ‘Settings – User’ preferences file (this is a JSON file), and add the following to tell ST2 to use the new theme:

"theme": "Soda Dark.sublime-theme",

You’ll notice a change straight away, but will probably need to restart ST2 for it to pick up all of the new theme properly.

Finally, I setup syntax highlighting to suit. ST2 ships with a number of these, and you can (if you wish) feed it any colour scheme originally created for TextMate. I prefer to use the ‘Phix Color Scheme’, which is available through Package Control.

Editing User Preferences

In ST2, nearly all of the configuration is done by creating and editing config files. There are no user interfaces to click through, just JSON files to edit by hand. There are a few of these files, and the basic idea is that there’s nearly always a ‘default’ config file (which contains the defaults that ST2 or its plugins ship with), and ‘user’ override files.

If you go into the Preferences menu, you’ll see a ‘Settings – Default’ option. This opens the default settings file that ST2 ships with. It’s very well documented, and well worth a browse through to see if there’s anything in there that you’d like to tweak. Don’t make changes to this file; instead, open the ‘Settings – User’ option on the Preferences menu, and put your changes in there. That way, your preferences will be preserved between ST2 upgrades.

Finding Classes With The Goto Anything Pane

There are two ways you can open files in ST2. One way is to navigate through your list of folders in the Project pane on the left hand side of the screen, clicking around with the mouse and drilling down to find the file that you’re looking for. It works … but there’s a faster alternative.

Hitting CTRL+P (CMD+P on the Mac) opens up the Goto Anything pane. Here, you can type in the name of the file that you’re looking for, and in real time, you’ll see a list of matches appear. The searching supports fuzzy matching; you can type in partial search strings, and ST2 will use them to filter out. This is a godsend for working with projects that include vendor folders (which you might not want to search inside), and any Subversion checkouts that include trunk, branches and tags.

Jump To A Line Using The Goto Anything Pane

Press CTRL+G (CMD+G on the Mac), and this brings up the Goto Anything pane, ready for you to type in a line number. As you type, ST2 goes to the line number starting to form in the input box. You can also do exactly the same by pressing CTRL+P and typing a colon at the start of the search. (CTRL+G simply opens the Goto Anything pane and puts the colon there for you as a shortcut).

You can also combine this with the file search. Hit CTRL+P and start searching for a file. Then, at the end of your search, add a colon, and then the line number that you’re looking for. This will take you to that line number in that file – all from the keyboard.

Goto A Defined Symbol Using The Goto Anything Pane

Press CTRL+R (CMD+R on the Mac), and this brings up the Goto Anything pane, ready for you to type in the name of a function or method. As you type, ST2 narrows down the list of matching functions, methods and classes in your file. You can do the same by pressing CTRL+P and typing an @ symbol at the start of the search.

You can combine this with the file search. Hit CTRL+P and start searching for a file. Then, at the end of your search term, add an @ sign, and then the name of the function or method that you’re looking for. This will take you to that function or method in that file.

Coding Quicker With The Additional PHP Snippets

The Additional PHP Snippets plugin [disclaimer: I’m the author of this plugin] provides a few simple text snippets to speed up everyday chores such as creating getters and setters, and add license text to the top of the file. It is available via Package Control.

Pull requests (or requests for features) are most welcome.

To use it, inside your PHP code, simply type ‘php-‘, and ST2 will show you a list of all of the matching snippets. Select the snippet you want, hit TAB, and hey presto – the snippet is dropped into your code, ready for you to adapt as required.

Creating Doc Blocks Using DocBlockr

The DocBlockr plugin makes it very quick and easy to create doc blocks for your classes, attributes, and methods. It is available via Package Control.

To use it, open a new doc block as normal by typing ‘/**’ and then pressing ENTER. The plugin will create a template doc block for you to fill out to suit.

Real-Time Syntax Checking Using SublimeLinter

Real-time syntax checking is something you take for granted with an IDE, and it’s available in ST2 in 2 main flavours. I use the SublimeLinter plugin myself, and have had no trouble with it at all, but I know that some folks have had to use the sublime-lint plugin instead. Both are available via Package Control.

Once installed, your code is checked in real time for syntax errors. Lines that contain syntax errors are highlighted, and in the status bar at the bottom of the screen, you’ll see an explanation of what the error is.

Sometimes, the syntax error will appear to be on the wrong line – on the line below where the real problem is. SublimeLinter uses the ‘php -l’ command behind the screens – PHP’s built-in linter, and is simply reporting back exactly what the PHP runtime thinks is wrong. This might puzzle you at first if you’re used to IDEs that have their own lint algorithm built in.

Consulting The PHP Manual Using Goto Documentation

The PHP Manual is, imho, PHP’s true killer feature: all that detailed documentation, and it’s all freely available on the web (no need to go away and buy books on the language). Like many PHP developers, I’ve always got the PHP Manual open when I’m working.

The Goto Documentation plugin allows me to look up any PHP function from inside ST2. The plugin is available via Package Control, and once installed, you need to bind it to a key before you can use it. This is done by opening the ‘Key Bindings – User’ option on ST2’s Preferences menu, and adding a line like the following:

{ "keys": ["f1"], "command": "goto_documentation" }

Save the file, and you’re ready to go.

To use it, just put your text cursor on the PHP function that you want to look up, and hit your chosen key combination. Goto Documentation will switch to your browser, and search the PHP Manual for the function you’ve selected.

Handling Trailing Whitespace Using The TrailingSpaces Plugin

I know it’s a small thing, but trailing whitespace annoys the crap out of me, and I’ve always been deeply frustrated with how Netbeans never reliably stripped this from files that I created or worked on. Thankfully this isn’t a problem with ST2, and you can add the TrailingSpaces plugin to strip files in between saving them.

Testing Using PHPUnit

The PHPUnit plugin [disclaimer: I am the plugin’s author] allows you to run your unit tests right from inside ST2. You can run the tests for just the file you’ve got open, or you can run all of your project’s unit tests in one go. You can also switch back and forwards between your PHP code and your unit test files, and you can quickly open your project’s phpunit.xml file.

To use the plugin, your project needs to have either a phpunit.xml file, or a phpunit.xml.dist file. This is a simple config file that tells PHPUnit where your tests are, which folders to include / ignore for code coverage purposes, and what reports / logs PHPUnit should create once the testing is done. If you’re using something like Phix, you get all of this for free, and I believe that Symfony’s standard app skeleton also includes a phpunit.xml file too.

The plugin navigates around your project, switching from file to file, using the following algorithm:

  1. It takes the full name of your PHP class, including the namespace, and uses the PSR0 autoloader algorithm to try and find the same class with ‘Test’ appended on the end. If that doesn’t work, it strips off the namespace and tries again.
  2. To find the phpunit.xml file, the plugin finds the test code first, and then searches each folder upwards for phpunit.xml or phpunit.xml.dist. If that doesn’t work, it looks in a number of pre-determined locations (defined in the plugin’s settings file), and then as a last resort it searches your whole project downwards starting from the top folder.

When you run your tests, the full output from PHPUnit appears in a panel at the bottom of ST2’s window – and that includes information on the full command executed, and which folder it was executed from. To close the panel, just hit ESC.

Alignment Plugin

This is a very simple plugin; it allows you to select some lines of code, and have all of the equals signs line up under each other. I find that this can make code (and especially array definitions) much clearer to read, but I know that it isn’t for everyone 🙂

Software Archaeology Using CTags

One of the ways that IDEs add a lot of value is that they truly understand the code you’re working on, and that allows them to offer features like ‘goto source definition’ et al. There’s a way you can do this in ST2, by installing the CTags plugin.

Once you’ve installed the CTags plugin, before you can use it, you need to go to the plugin’s website and follow the instructions there to get a suitable ‘ctags’ command line program installed. The plugin is a wrapper around this command’s functionality, and cannot work without it.

Then, the next step is to build a tags file. This is an index of all of your code, that the plugin can use to look up classes, functions and methods so that you can quickly jump to their definition from anywhere in your project. This is done by hitting CTRL+T and then CTRL+R, and then waiting for the ‘finished building’ message to appear in the status bar.

After that, you can navigate around your code by hitting CTRL+T and then CTRL+T again. This works particularly well for exploring code you haven’t seen before, something that I demo in the video below.

One last word of advice. CTags understands the syntax of your code, but not the strategy. It doesn’t understand the difference between trunk/ and branches/ folders, for example, or vendor/ folders. If there’s code in there, CTags by default will index it. This might be what you want, but if you find that it’s picking up duplicates that you’re not interested in, you’ll need to create a CTags.sublime-settings file in your User/ package folder to override the ctags_command setting and add in some exclusions.

What Else?

There’s one notable exception that I haven’t covered here, and that’s SublimeCodeIntel. This is a plugin that aims to bring Komodo’s autocompletion over to ST2. It’s a great idea, but my own experience with the plugin isn’t good. I’ve seen it installed on two different computers running the same OS and version of ST2, and it work fine on one and not work at all on the other. I’ve seen it stop working after a new version of the plugin was released. I’ve learned to live without it. But do go try it out, because if it works for you, you might really like it.

Are there any other ST2 plugins that you use on a daily basis? Mention them in the comments below, and I’ll check them out 🙂

111 comments »
Page 3 of 1912345...10...Last »

This Month

October 2018
M T W T F S S
« Sep    
1234567
891011121314
15161718192021
22232425262728
293031