Reworked the PHP part again

Yeah I think this is a better design.

More tests coming soon.