i have problem with a nodejs script used from php using exec() in a loop . the problem is that the script is executed only once then just errors. here is the php code :
for ($i=0; $i <= ((mysqli_num_rows($repp)/50)-1); $i++)
{
$req = "select * from items limit ".$id.",50";
$rep = mysqli_query($link,$req);
$names = "";
$id = $id + 50;
while($donne = mysqli_fetch_array($rep))
{
$names = $names.$donne["item_name"].',';
}
$resultat = '"'.rtrim($names, ",").'"';
exec("node node_opskins.js ".$resultat,$out);
$result =implode($out);
$a = str_replace("'", '"', $result);
$a = preg_replace('/([\w\d]+): /', '"$1": ', $a);
foreach ( json_decode($a,true) as $key => $value)
{
echo $key . " : " . $value['market_price'] . "<br/>";
$req = "update items set opskins_suggested = '".($value['market_price']/100)."' where item_name = '".addslashes($key)."'";
mysqli_query($link,$req);
}
sleep(10);
}
and here is the Nodejs script :
var OPSkinsAPI = require('@opskins/api');
var opskins = new OPSkinsAPI(my opskins api key);
var item = process.argv[2].split(",");
opskins.getSuggestedPrices(730, item, function(err,price){
console.log(price);
});
via ishak hadje
No comments:
Post a Comment