When projects scale to a certain size, a framework is inevitable. You can explicitly choose a framework, or you can implicitly accrete it. If you do not explicitly choose to design / adopt a framework or architecture, you will still have one, it will just be a very badly designed one, and it will be much harder to add new functionality without introducing bugs (as you have already experienced). If you do not yet have the skill to design your own framework, it is better to choose a well-known framework, as it will save you time in the long run.
Specifically about your examples:
Youtube uses python for its front-end, but it spends most of its time in back-end services. In large sites you typically find this architecture where everything that takes up considerable time is moved out of the front-end servers and into a back-end service layer which can be scaled independently from the front-end. From what I can find they seem to have rolled their own framework. For more info, see http://highscalability.com/youtube-architecture
Facebook uses PHP for its front-end, and they also spend a lot of time dispatching to back-end services. Again their framework is home-grown, but they have even gone so far as to build their own PHP engine and development tools. They've open-sourced some of their framework code as well.