I have an upcoming trip where I will be flying to and from Copenhagen, through Toronto. I notice that my departure and return gate in the Philadelphia airport is not in the international terminal.
Where will I clear customs?
Flights leaving the US to Canada do not have any special customs issues on the way out. You won't interact with customs or immigration as a general rule. Many people will look at your passport: the people before you go into security, the gate staff before they let you on the plane, etc, but they are just making sure you are likely to be accepted where you're going or that your name matches your ticket.
When you get to Toronto, you will probably need to clear Canadian customs (you tell them you're in transit) and then go to the international area, where there won't be any customs or immigration related to leaving Canada. For some flights, you can "stay airside" and not interact, or interact only very briefly, with Canadian customs and immigration.
When you get to Copenhagen, you will interact with Danish customs and immigration who will let you into the country.
On the way home, you will probably have to deal with the "leaving" customs and immigration, that's what I've experienced in general leaving Europe and I've left Copenhagen and recall walking FOREVER to the far end of the airport where they had the customs people for the outgoing fights. At least I think that was Copenhagen.
In Toronto you may again have a brief interaction with Canadian customs and immigration, and then you will meet US customs and immigration for the pre-clear. To enable more US airports to be served from Canada, you get admitted to the US while you're still in the Canadian airport. At that point your plane can now land in the domestic part of the US airport (which for many small airports is the entire airport) and when you land you can just head out of the airport, you're all set.
If you are flying to the United States from Toronto-Pearson (YYZ) to Philadelphia, and you are being routed to a "domestic terminal" that means that you have to clear US Customs at the Preclearence Facility at YYZ. Essentially, you will be clearing customs before entering the country.
You will then have to clear Canadian Customs and Danish Customs on the return trip (in Toronto YYZ and Copenhagen)
The US has preclearance at the following Canadian airports:
If you board a US-bound flight at any of these airports, you will pre-clear US customs at the Canadian airport, and then arrive in the US as a domestic passenger. (It is theoretically possible that you could be required to re-clear US customs and immigration at the US airport, but this is very, very rare and only apparently done if there is some evidence of a problem with the preclearance process).
Originating from or connecting through any other Canadian airport to the US (e.g. YQR Regina), you will clear US customs at the destination airport, as per normal international arrival process.