私はAPIからすべてのデータをダウンロードしようとしているので、それを丸め、結果をjsonファイルに保存しています。しかし、実行は停止し、結果は切り捨てられ、決して終了しません。
これはどのように修正できますか。たぶん、API のサーバーでの最大実行時間はそれほど長くサービスを提供できず、停止します。10000以上の結果があると思います。
最初の1000件、2番目の1000件などをダウンロードする方法はありますか?
これが私のコードです:
<?php
$url = 'http://api.example.com/model';
$data = array (
'app_id' => '234567890976',
'limit' => 100000
);
$fields_string = '';
foreach($data as $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; }
$fields_string = rtrim($fields_string,'&');
$url = $url.'?'.$fields_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '300000000');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
print($response);
$file = fopen("results.json", 'w+'); // Create a new file, or overwrite the existing one.
fwrite($file, $response);
fclose($file);
curl_close($ch);