Cron作业没有运行特定的PHP文件

I have two PHP cron jobs running. In one cron job, am trying to open a file and write some data into it which works fine.

But in the other file, I have added an error_log() statement which is not getting printed into the log file. But the error_log file is getting updated when i manually run this php file. What could be the problem here that it doesn't write to the error_log.txt file only for cron job cases. [Note: The error_log.txt gets updated when i run the php file manually ]

Working cron:

<?php

$fp = fopen('/home/victor/public_html/victor_php/test/test.txt', 'a');
fwrite($fp, '    Cron test job   ');
fclose($fp);

?>

Not Working cron:

<?php

error_log("Cron1 test job",0);

?>
douyao7390
douyao7390 权限是我的第一个想法,在命令行上你可以访问,但cron可能没有。查看用户cron运行的内容,然后以该用户身份登录,看看它是否有效。否则就像在使用不同的用户时将苹果与橙子进行比较。
大约一年之前 回复
doupacan2098
doupacan2098 哪个用户运行crontab?root或apache?
大约一年之前 回复
dongzh1988
dongzh1988 请创建一个测试表并在测试表中插入数据进行测试
大约一年之前 回复
duangu4943
duangu4943 你怎么知道它没有运行?
大约一年之前 回复
drs3925
drs3925 更新了上面的代码
大约一年之前 回复
duananyu9231
duananyu9231 没有代码,甚至无法猜测
大约一年之前 回复

1个回答



我刚刚发现我的cron作业中给出的error_log登录到根目录的error_log。 当我们手动运行php文件时,日志会记录到当前目录中的error_log文件中,而cron作业则不是这样。 这就是混乱。</ p>

谢谢大家的支持。</ p>
</ div>

展开原文

原文

I just found that the error_log given in my cron job was logging into the error_log of root directory. When we run the php file manually the logs get logged into the error_log file in the current directory, and this is not the case with cron jobs. That was the confusion.

Thank you all for the support guys.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问