Measuring the phase difference between two signals
Solution for analog signals:  

if you simply subtract both signals you get a signal whose amplitude will increase with increasing phase difference:  



As the purple signal's phase shifts the difference signal's amplitude increases. The error signal is zero when both signals are in phase (at t = 5).



Here both signals start out at the same phase, and the difference signal is only caused by the difference in amplitude. So you'll have an offset if both signals don't have the same amplitude. If \$P\$ = \$A\$ - \$B\$ then applying an envelope detector (peak detector) to all three signals gives you \$Phase\$ = \$A_p\$ - \$B_p\$- \$P_p\$.