I am seeing a very bizarre problem with a PHP application I am building.
I have 2 virtual hosts on my development server (windows 7 64-bit) sometestsite.com
sometestsite.com
Be sure that you run script on console from same user that used for run cgi process. If they not same - they may have different permissions. For me problem was in firewall rules that disallow open external connections for owner of cgi process.