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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题