dongse7261 2014-12-12 20:09
浏览 73

在对Highrise API执行CURL请求时,循环挂起

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 (xxxx@xxxxxx.com)'
        ));

        $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);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
    • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
    • ¥15 opencv图像处理,需要四个处理结果图
    • ¥15 无线移动边缘计算系统中的系统模型
    • ¥15 深度学习中的画图问题
    • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条