I am having trouble getting this code to execute properly. The way the Highrise API works is that it will only return 500 results in each request, to get more results you add the ?n=number
to the end of the URL. I have almost 9000 entries and I need to loop through every single one of them and extract information based on some conditional statements.
My goal is to loop through this function and each time add 500
to the end of the URL getting the additional 500 entries. For testing I only had it loop 3 times but for some reason it just hangs and never returns anything. I understand that it is retrieving a large amount of data per request so I have waited up to 3 minutes with no luck.
I have checked my error logs and do not see any errors. Maybe I am executing the curl
command improperly inside of the loop. If I remove the first for
loop I get back the first 500 results as expected.
<?php
$curl = curl_init();
function runScript($curl) {
for($currentCount = 0; $currentCount <= 1000; $currentCount + 500) {
//set parameters to be used for curl options
curl_setopt_array($curl, array(
CURLOPT_USERPWD => 'xxxxxxxxxxxx:X',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://xxxxxxx.highrisehq.com/people.xml?n=$currentCount",
CURLOPT_USERAGENT => 'XXXXXXXXX Test App ([email protected])'
));
$resp = curl_exec($curl);
$xml = new SimpleXMLElement($resp);
foreach($xml->person as $person) {
if($person->{'subject_datas'}) {
foreach($person->{'subject_datas'}->{'subject_data'} as $subjectData) {
if($subjectData->{'subject_field_id'} == 780666) {
echo $person->{'first-name'};
echo ", ";
echo $person->{'last-name'};
echo ", ";
echo $person->{'title'};
echo ", ";
echo $person->{'company-name'};
echo ", ";
foreach($person->{'contact-data'}->{'email-addresses'} as $email) {
echo $email->{'email-address'}->{'address'};
}
echo ", ";
echo $subjectData->{'value'};
echo "<br/>";
}
}
}
}
}
}
runScript($curl);
curl_close($curl);