A: 

The $parent_id you provide in the recursive call will always be the same as the one that was used on your first call, since it's not modified anywhere in your code as far as I see. So that's your problem, you create an infinite loop by calling the same function with the same parameters over and over again.

wimvds