我有一个非常费力的
PHP脚本,它可以在其他地方对服务器进行几次api调用.
我需要运行此脚本以保留我的服务器上的某些数据,与远程服务器上的数据同步.
我希望每次特定类型的用户访问特定页面时都会启动此脚本.
但问题是,如果符合条件的用户访问此页面,则页面加载时间是非常多的,即使脚本处理的数据不会以任何方式影响页面本身.
所以,我想知道的是,我如何使用相同的条件运行此脚本,但只在我的服务器上运行它?
换句话说,我如何运行此脚本并阻止浏览器等待其输出?
编辑:有用的信息:使用XAMPP for Windows,PHP 5.5,Apache 2.4.
编辑2:使用curl似乎是最好的选择,但它不想实际运行我的脚本.
这是电话:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/tool/follow/PriceTableUpdate.php');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1);
curl_exec($ch);
这是实际的PriceTableUpdate.php:
ini_set('max_execution_time', 3600);
$marketData=simplexml_load_file("http://www.eve-markets.net/api/xml?listid=20158key=JKgLjgYvlY6nP");
foreach ($marketData->marketList->type as $type) {
$ItemID = (int)$type['id'];
$ItemBuy = $type->buy->price;
$ItemSell = $type->sell->price;
$ItemMedian = $type->median->price;
mysqli_query($con,"UPDATE piprices SET `ItemBuyPrice` = $ItemBuy, `ItemSellPrice` = $ItemSell, `ItemMedianPrice` =$ItemMedian WHERE `piprices`.`ItemID` = $ItemID");
}
?>
编辑3:
使用上述DOES工作,以防有人想再次提出这个问题.
你必须记住,因为你使用curl,php文件不再使用你之前设置的变量,所以你需要再次在php文件中定义你的数据库连接.