i'm getting the exact same issue and can't seem to resolve it.
i'm using the standard jsonrpc.php which i've used in other projects so i can't see why it's not working for me at the moment.
right before the fopen, i've echoed the url and the json string to check it, and then went to an online validator (
http://jsonlint.com/) which told me the json was valid.
yet i still get the 500 error.
php.ini says yes to allow_url_fopen, and safe_mode is off.
i've tried restarting apache, and tried restarting bitcoin.