A court can't grant you a divorce unless it has jurisdiction over the case, and it may be limited as to what it can order if it doesn't have jurisdiction over both you and your spouse. Jurisdiction is a tricky phrase, however, because it can be achieved in more than one way.
Bona Fide Residency
You don't have to be a resident of Pennsylvania to file for divorce in the state, provided your spouse is a resident. One of you must have lived there for six months, and these six months must occur immediately before you file. For example, if you lived there years ago, then you moved to New Jersey, you can't file in Pennsylvania unless your spouse resides there. The state's family code cites that one of you must be a "bona fide" resident, meaning you maintain a residence there to which you'll return if you leave for short absences, such as a vacation.
If you reside in Pennsylvania and your spouse lives elsewhere, the court can grant you a divorce, but it might not be able to do much else unless you have him officially served with your divorce papers. If he's not a resident, and if you don't know where he is to serve him with your papers, the court can't rule on things like equitable distribution of your property or anything that affects him financially.