为什么crontab -e不能执行fwrite写入文件?蹦溃了。
function write_filefun_new($filename,$filedir, $htmldata = '') {
if(!is_dir($filedir)) {
mkdir($filedir, 0777);
}
$htmlfile = $filedir.$filename;
if($fp = fopen($htmlfile, 'wbt')) {
fwrite($fp,$htmldata);
fclose($fp);
} else {
echo can not write to files, please check directory $htmldir.
;
exit;
}
}
$testnum_temp=;
write_filefun_new(test.php,inc/, $testnum_temp);
用浏览器运行页面是正常写入的,
在crontab -e中设置定时每分钟执行一次没有写入文件,crontab -e定时执行是正常,可以每分钟执行一次。
为什么会这样,就差这一个地方了,其它程序都正常执行,就差这个不能写入。为什么啊?
------解决方案--------------------
inc/ 是相对路径
请先弄清楚是相对谁的
------解决方案--------------------
看看日志,有什么警告信息吗?
------解决方案--------------------
你把crontab里面的命令直接在命令行运行一下看看什么反应
------解决方案--------------------
写一个sh,处理好权限 在这个文件里调用/usr/bin/php /var/www/html/write.php 最后在crontab 使用root 身份调用..