Improve error handling in PHP part

Change-Id: Iea5978e3a76194de63148386c0281af29477fb6d