drq1257 2015-02-26 10:49 采纳率: 0%
浏览 124
已采纳

PHP:使用file_get_contents的大量请求

I currently have a db table filled with organisation numbers [1,002 million rows].

Now, what im trying to do is fetch the phone number of the organisation from a remote website API. I've got this working, but just after 30-50 or so requests to the API, i dont see any new changes to the table im inserting the phone numbers into. I've still got 1 million++ rows to fetch the phone number from, but i cant seem to get further than a small amount of rows.

Thanks in advance for the help.

I dont know if this is gonna help, but here is the code im using to do this.

// Remove timeout limit
// This is going to take alot of time!
set_time_limit(0); 

// Initialize...
include $_SERVER['DOCUMENT_ROOT'] . '/core/Init.php';

// Profiles
$url = 'http://finnrett.no/API/business/get/quickresults?q=';
$profile_url = 'http://finnrett.no/API/business/get/profile?id=';

// Select names
$sql = 'SELECT organisasjonsnummer FROM brreg  ORDER BY id LIMIT 10000';
$result = $Dbh -> query($sql, []);

// Each name
foreach ($result as $orgnr) {

    // Pre for output explananation
    echo'<pre>';

    // Grab json from quick results url
    $bedrift = json_decode(file_get_contents($url.$orgnr['organisasjonsnummer']));
    $ID = get_object_vars($bedrift[0])['ID'];

    $profile = json_decode(file_get_contents($profile_url.$ID));
    $CONTACT = get_object_vars($profile);
    $number = $CONTACT['contact'] ? $CONTACT['contact']: '0';

    $sql = 'INSERT INTO profiles (orgnr, telefon) VALUES (:orgnr, :telefon)';
    $args = ['orgnr' => $orgnr['organisasjonsnummer'], 'telefon' => $number];
    if (!$Dbh -> query($sql, $args)) {
        echo 'Sjekk opp org: ' . $orgnr['organisasjonsnummer'] . ' fordi her skjedde det noe galt.';
    }


}

Looks like i solved it by choosing curl instead of file_get_contents.

  • 写回答

1条回答 默认 最新

  • douyan1896 2015-02-26 14:39
    关注

    Solved it by switching to curl instead of file_get_contents()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题