I have found topics on ways to merge JSON data but nothing specifically like what I'm trying to do. The API I'm requesting data from has an upper limit of 1000 results at a time from their database. I am able to pull 1000 results just fine if I search between a span of today until one year out. I'm not getting all the results though. Talking to their tech, they suggest that I tailor multiple API requests to pull 1000 from every 30 days in succession, then merge them. I'm not sure how to do that.
The request:
// Get date + 30 days to use in the request:
$endDate = date('Y-m-d',strtotime(date("Y-m-d", mktime()) . " + 30 day"));
$url = PROTOCOL . '://'. ENDPOINT . '?api_key='. API_KEY .'&api_secret='. API_SECRET;
$url .= '&aflt_token=K4RrVSQJFt51F2kyFXDZDFlE9igOtuM4';
$url .= '&format=json';
$url .= '&events=T';
$url .= '&race_headings=F';
$url .= '&race_links=F';
$url .= '&include_waiver=F';
$url .= '&page=1';
$url .= '&results_per_page=1000';
$url .= '&start_date=tomorrow';
$url .= '&end_date='.$endDate;
$url .= '&only_partner_races=F';
$url .= '&only_races_with_results=F';
$url .= '&distance_units=K';
$json = file_get_contents($url);
$json_output = json_decode($json);
They suggest I make similar calls for each successive 30-day period, modifying:
$url .= '&start_date=tomorrow';
$url .= '&end_date='.$endDate;
to the next 30 day span each time. So realistically I could make 6 separate calls to get a full 6 months. The question is how to make these calls then merge the data that's returned. It's all exactly the same/format and all getting put into the same database. Thanks for any insight.
UPDATE: I am able to merge separate, 30-day requests for the max results (1000 apparently) from the API by using
$merged_data = array_merge(array($json_output, $json_output2, $json_output3, $json_output4, $json_output5));
BUT: the maximum number of requests I can make seems to be limited (only 4, 30-day periods of 1000 results) before I get a memory error: " Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 83 bytes) in /home/runraceitadmin/public_html/dev/runsignup.php on line 165"
So it seems the max number of records I can get from the API this way is 120 days worth. I am looking to pull a full calendar year.