I've never transitioned from one foreign country to another through SFO and I think you might have to go through customs anyway -- the planes don't land at the int'l boarding areas, unless there's another way from arrivals to departures; I've never had to look. Customs is pretty quick at SFO and the int'l terminal is awesome. ^ 5 hours? You're fine. I've arrived for int'l flights one hour before departure w/o problem. The int'l terminal has an int'l food court by the check in areas you could meet your friend at.