【发布时间】:2016-05-27 06:07:26
【问题描述】:
我已经为此努力了好几个小时了。
我正在通过 cron 作业执行一个 php 脚本,除了 exec() 方法之外,脚本中的所有内容都可以正常工作。
<?php
exec('gpio write 7 0');
// Open the file to get existing content
$current = file_get_contents('log.txt');
// Append a new person to the file
$current .= get_current_user().' - '.date('H').":".date('i')." - gpio write 7 0\n";
// Write the contents back to the file
file_put_contents($log, $current);
?>
如果我直接从终端执行 php 脚本,则它适用于 pi 用户和 root 用户。
cron 作业运行时写入log.txt 文件的数据对我来说看起来不错,这是一个示例:
root - 00:16 - gpio write 7 0
root - 00:17 - gpio write 7 0
root - 00:18 - gpio write 7 0
root - 00:19 - gpio write 7 0
我尝试为要执行的 php 文件提供 755 和 777 权限,但没有成功。
这是我执行sudo crontab -e时的结果
*/1 * * * * /usr/bin/php /var/www/check_time.php
任何帮助将不胜感激。
提前致谢。
【问题讨论】:
标签: php bash cron raspberry-pi gpio