PHP API v2

Another possible candidate for a refactor to, for example, `flush_buffer_and_assert_output_equal`?