大家好我从Steam的数据库中获取大约1.3k的记录,我想知道如何加速我的脚本。
目前我在他们的API网址上使用file_get_contents为每个应用程序的ID循环(所以这是发送1.3k请求,你可以想象这很慢)。
有更好的方法吗?我们曾经将所有应用程序的ID集中在一起,但他们已经删除了这种能力,我们现在必须一次做到这一点,并且它并不好。
这是显示循环的代码:
foreach($Chunks as $Game)
{
if ($Game['bundle'] == 0)
{
$Subs_URL = 'http://store.steampowered.com/api/packagedetails/?packageids=' . $Game['steam_appid'] .
'&cc=' . $cc . '&filters=basic,price_overview';
if ($JSON = file_get_contents($Subs_URL))
{
$DecodedJson = json_decode($JSON,true);
foreach($Chunks as $Chunk)
{
if (!isset($DecodedJson[$Chunk['steam_appid']]['data']['steam_appid']))
{
$DecodedJson[$Chunk['steam_appid']]['data']['steam_appid'] = $Chunk['steam_appid'];
}
}
//echo '<pre>';
//print_r($DecodedJson);
//print_r(array_keys($DecodedJson));
$GameList = array_merge($GameList,$DecodedJson);
}
else
{
die("Steam API timed out!");
}
}
以下是$ Chunks的例子:
array(1358) {
[0]=>
array(4) {
["steam_appid"]=>
string(6) "227580"
["name"]=>
string(10) "10,000,000"
["dlc"]=>
string(1) "0"
["bundle"]=>
string(1) "0"
}
[1]=>
array(4) {
["steam_appid"]=>
string(6) "206712"
["name"]=>
string(21) "Cities in Motion: Ulm"
["dlc"]=>
string(1) "1"
["bundle"]=>
string(1) "0"
}
[2]=>
array(4) {
["steam_appid"]=>
string(6) "259620"
["name"]=>
string(24) "3079 -- Block Action RPG"
["dlc"]=>
string(1) "0"
["bundle"]=>
string(1) "0"
}