First of all, the definition of a companion has never been made clear, which makes this question difficult to answer (see HELP:COMPANION for more info), but as most of the Doctor's companions have been human or travelling with him at the same time as a human, it is reasonable to assume that, at least on television, Handles is one of the longest serving companions, potentially the longest serving companion, due to the amount we have seen the humans age. However, there are still problems with that idea. It can be assumed the year length on Trenzalore wouldn't be exactly the same as on Earth due to how incredibly unlikely that would be to happen on a cosmic scale, which makes it uncertain just how long those 300 years actually were in relative Earth time. Even then, one must take into account whether time serving is relative to the Doctor or to the companion. If the former, the Brigadier would most probably out-serve Handles, as he first met the Doctor when the Doctor was in his Second incarnation, and last met (on screen) when the Doctor was in his Seventh incarnation, most likely more than 300 years later from the Doctor's perspective. However, this was still only over the course of the Brigadier's adult life, much less than 300 years of companionship from the Brig's perspective. Also, the Brigadier is one of those individuals whose companion status is disputed.
If you regard the TARDIS as a companion (which some fans do), she easily beats all other contenders for the title of "longest serving companion".
So, in short, Handles might or might not be the longest serving companion, depending on perspective, however he is certainly one of the longest serving companions.