gpt4 book ai didi

PHP:使用 file_get_contents 进行大量请求

转载 作者:行者123 更新时间:2023-11-29 22:55:18 25 4
gpt4 key购买 nike

我目前有一个数据库表,其中填充了组织编号 [10.02 亿行]。

现在,我想做的是从远程网站 API 获取组织的电话号码。我已经完成了这项工作,但在向 API 发出 30-50 个左右的请求后,我没有看到插入电话号码的表有任何新的更改。我仍然有 100 万行++ 行来获取电话号码,但我似乎只能获取少量行。

预先感谢您的帮助。

我不知道这是否有帮助,但这是我用来执行此操作的代码。

// 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.';
}


}

看起来我通过选择curl而不是file_get_contents解决了这个问题。

最佳答案

通过切换到curl解决了这个问题而不是file_get_contents()

关于PHP:使用 file_get_contents 进行大量请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28740410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com