我使用curl检索当前股价的价值,我创建了几个cron作业,每20分钟左右更新一次股票的价值。昨天它运行正常,但从今天起它突然返回null对象,我使用curl进行值检索。
以下是代码:
$sourceURL = 'http://www.google.com/finance/info?infotype=infoquoteall&q='.$row[1].':'.$main_id;
echo $sourceURL."<br/>";
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $sourceURL);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$sourceData = curl_exec($ch);
curl_close($ch);
$json = str_replace("\n", "", $sourceData);
//Remove //, [ and ] to build qualified string
$data = substr($json, 4, strlen($json) -5);
//解码JSON数据
$json_output = json_decode(utf8_decode($data));
var_dump($json_output);
//输出股票价格 // update_in_DB返回查询字符串,如底部
$query=update_in_DB($json_output,$main_id);
$result_query=mysqli_query($dbc,$query);
if($result_query===false)
{
echo mysqli_error($dbc)."<br/>";
}
echo "done<br/>";`
这正如我所说的那样正常但现在update_in_DB重新出现了这个:
UPDATE `stock_table`
SET `stock_curr_val`=0, `stock_change`=0, `stock_change_p`=0, stock_open_val`=0, `stock_hi_val`=0, `stock_low_val`=0, `stock_volume`='0', stock_hi_52`=0, stock_low_52`=0, `stock_market_cap`='0'
WHERE `stock_symbol`='20MICRONS';
感谢您的帮助。