Use resources in php54 and fix issues