HTTP code 0 usually means the request isn’t leaving your machine at all – perhaps due to incomplete SSL settings in your PHP or perhaps due to some kind of firewall issue. Do you have a PHP error log file accessible to you? It might have more information within.
To run a script like this from a non-web context, open up a terminal window to get to a command line. Change to the directory where you have the script. And use the command like:
php filename.php
You may want to go a little more complicated in your debugging in the file. Instead of just echoing $response, I would recommend doing an object dump on it instead – perhaps you’ll then see more about the error disposition that way.