Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php exec()未通过cron作业运行_Php_Bash_Cron_Raspberry Pi_Gpio - Fatal编程技术网

php exec()未通过cron作业运行

php exec()未通过cron作业运行,php,bash,cron,raspberry-pi,gpio,Php,Bash,Cron,Raspberry Pi,Gpio,几个小时以来,我一直在用头撞这个 我正在通过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().

几个小时以来,我一直在用头撞这个

我正在通过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文件赋予
755
777
权限,但没有成功

这就是我在执行
sudo crontab-e

*/1 * * * * /usr/bin/php /var/www/check_time.php
任何帮助都将不胜感激

提前感谢。

在线

exec('gpio write 7 0);
应该是吗

exec('gpio write 7 0');

??“似乎从未关闭过。

您应该指定
gpio
的路径,并给出确切位置,以便cron知道在哪里可以找到它,
/usr/local/bin
不是由cron导入的:

/usr/local/bin/gpio
那么它将是:

exec('/usr/local/bin/gpio write 7 0);

不,那是我写这篇文章时的一个打字错误。不过这是个好主意。我已经相应地更新了帖子。感谢您在哪台计算机/服务器操作系统上运行它?似乎php没有执行脚本。在较新的ubuntu服务器上,您只需使用
php
,而不用cron脚本中的
/usr/bin/php
。他们中的一些人对编辑很挑剔——我看到你说你在ras pi上运行它,试试看
exec('/usr/local/bin/gpio write 7 0);