我有一个带有IF语句的脚本,该脚本检查XML的特定值。该文档每30秒刷新一次,如果在XML中找到该值,则执行命令。有什么方法可以使脚本每15分钟执行一次,而不是每隔30秒刷新一次XML?
$xml = 'http://www.example.com/xmlfile.xml';
if ($xml->value == '1')
{
// Exectute something if value from the XML is 1.
}
else
{
// Value not 1, do nothing.
}
$fileName = "lastrun.txt";
$time = file_get_contents($filename);
$timeBetweenRuns = 15;
if(!$time || time() > $time+60*$timeBetweenRuns){//if no file or time elapsed more then timeBetweenRuns
//Your code read file
if($xml->1){
//Your code .. Only thing if it may take more then next run, you need to add lock to not allow two process do same thing
file_put_contents($filename, time())
}
else{//Your code
}
}
这样的事情。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句