このコードを使用して、Apple のサーバーに対してアプリ内受信確認を実行しています。このスクリプトが実行される時間の約 50% で、すべてが正常に機能します。ただし、残りの 50% の時間では、空の json 応答が返されます。例外はありません。理由はありますか?
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$meta = stream_get_meta_data($fp);
print_r($meta);
stream_set_timeout($fp, 200);
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
$appleURL = "https://buy.itunes.apple.com/verifyReceipt";
$receipt = json_encode(array("receipt-data" => $receiptdata));
$response_json = do_post_request($appleURL, $receipt);
$response = json_decode($response_json);
var_dump($response_json);
これは、ストリーム メタデータを var_dump したときに得られるものです
array(10) { ["wrapper_data"]=> array(2) { ["headers"]=> array(0) { } ["readbuf"]=> resource(6) of type (stream) } ["wrapper_type"]=> string(4) "cURL" ["stream_type"]=> string(4) "cURL" ["mode"]=> string(2) "rb" ["unread_bytes"]=> int(0) ["seekable"]=> bool(false) ["uri"]=> string(42) "https://buy.itunes.apple.com/verifyReceipt" ["timed_out"]=> bool(false) ["blocked"]=> bool(true) ["eof"]=> bool(false) }