我有一个 cron 作业,我设置为每五分钟运行一次。因为这个 cron 作业不是通过 apache 运行的,我相信如果它最终触及网站的服务器端缓存文件(它经常这样做),这些缓存文件最终将不再被 apache 写入,所以我得到了所有这些关于每次我在浏览器中运行网站时都无法写入缓存文件的错误。有什么办法可以让它没有这个问题吗?在 Centos 6.4 上运行网站,以防万一。
最佳答案
这个问题至少有两种解决方案,都涉及使用 chmod
和 chown
.
解决方案一:
将您的 cronjob 运行的任何内容移动到它自己的 shell 脚本中,并告诉 cron 运行您的 shell 脚本。
原始命令运行后,运行 chmod
和 chown
根据需要更改权限。
#!/bin/sh
printf "Do your stuff here\n"
DIR_ROOT="./your-dir-here/"
find $DIR_ROOT -type f -print0 | xargs -0 chmod 664 # make all files user+group r+w
find $DIR_ROOT -type d -print0 | xargs -0 chmod 775 # make all directories user+group r+w+x
chown apache:apache -r $DIR_ROOT
方案二:
您可以在 cronjob 运行的命令上附加一个分号,而不是使用 shell 脚本,然后添加
chmod
和 chown
.*/5 * * * * /my/five/minute/script.sh; chmod 664 ./some-file; chown apache:apache ./some-file
希望有帮助。
注意:这两种解决方案故意不一样,我希望您尝试通过这种方式思考。
关于php - Cron 使缓存文件不可写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25025888/