php读写文件失败

时间:2016-08-20 22:47:10

标签: php bash crontab

当功耗突然超过阈值时,我试图用推送消息向自己发送垃圾邮件。 我每分钟收集数据。 cronjob从我的SMA转换器和智能电表收集数据。 这些数据放在字符串中。 我做了一些减法,收集的结果被放入一个文件中。 在接下来的一分钟间隔内,收集新数据。 旧结果从文件中提取。 如果阈值通过,则新旧比较显示。 然后将最新结果再次放入文件中。 该文件名为usage.txt

if (!$handle = file_get_contents('/home/pi/test/usage.txt'))
{
    // failure
    echo "error opening the file usage.txt for reading",PHP_EOL;
}
else
{
    $lastusage=$handle;
    echo ' Last usage and current usage`           :  '.$lastusage.' '.$currentusage, PHP_EOL   ;
}

if(!file_put_contents("/home/pi/test/usage.txt",$currentusage))
{
    // failure
    echo "error opening the file usage.txt for writing",PHP_EOL;
}

这个读写不会触发错误消息,但在usage.txt文件中,10是写的而不是630或1240,这是我期望在usage.txt中插入的实际字符串。

0 个答案:

没有答案
相关问题