in reply to PayPal IPN Script End of script output before headers:

Hope you can help

See the Basic Debugging Checklist for how to help yourself. A consistent indent style wouldn't hurt either.

If I had to guess I would say that this

if ($res->is_error) { # HTTP error }

is being triggered, perhaps caused by this

SSL_version => 'SSLv23:!TLSv12'