Add valgrind check to php tests
Fix memory leaks reported by valgrind