Hmmm, there are alot of things to consider re: the workings of the Physics Engine before we go too indepth into your code:

a) what is your gravity set to? (ph_setgravity)
b) what is your elasticity set to? (phent_setelasticity)
c) do you have any of the corrections set and what to? (phent_setmasspeed and ph_setcorrections)

Perhaps in answering this question and messing with these parameters you get more stable behaiviour. Otherwise, post you settings (or lack thereof) and we can take it from there.