The Daleks themselves said in "Asylum of the Daleks" that it was known throughout the universe that The Doctor requires companions in his travels. They didn't know why, but they acknowledged that it was so. He's had dozens, maybe hundreds of them in his running through all of time and space. Some last only a brief while, while others stay with him for what seems like ages. Who is the longest serving companion? Well, that depends on how you measure it.
Jamie McCrimmon accompanied the Second Doctor in 113 episodes, far more than any other companion. Frazer Hines happened to be working on the show during one of its busiest times ever and stayed with the program at the request of Patrick Troughton who wished to have Jamie and The Doctor together until the end.
In terms of who has been in the most stories the clear winner is Amy Pond. She was with the Eleventh Doctor in 25 separate television adventures. Rose Tyler is the only companion to travel with a Doctor on every single one of his televised (and in Nine's case prose as well) outings. Jamie comes in second, having missed only "The Power of the Daleks" in Troughton's era.
If you consider how long they were on the show then Tegan Jovankan has the longest tenure, just narrowly beating out Sarah Jane Smith. Janet Fielding held the role for just under three years. Her and Elizabeth Sladen are the only two companion actresses to have featured in four consecutive seasons.