Rewrite PHP API

Fixes #191 : all PHP API has be rewritten.