php - Cron 使缓存文件不可写

标签 php permissions cron centos

我有一个 cron 作业,我设置为每五分钟运行一次。因为这个 cron 作业不是通过 apache 运行的,我相信如果它最终触及网站的服务器端缓存文件(它经常这样做),这些缓存文件最终将不再被 apache 写入,所以我得到了所有这些关于每次我在浏览器中运行网站时都无法写入缓存文件的错误。有什么办法可以让它没有这个问题吗?在 Centos 6.4 上运行网站,以防万一。

最佳答案

这个问题至少有两种解决方案,都涉及使用 chmodchown .

解决方案一:

将您的 cronjob 运行的任何内容移动到它自己的 shell 脚本中,并告诉 cron 运行您的 shell 脚本。

原始命令运行后,运行 chmodchown根据需要更改权限。

#!/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 脚本,然后添加 chmodchown .
*/5 * * * * /my/five/minute/script.sh; chmod 664 ./some-file; chown apache:apache ./some-file

希望有帮助。

注意:这两种解决方案故意不一样,我希望您尝试通过这种方式思考。

关于php - Cron 使缓存文件不可写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25025888/

相关文章:

php - 如何获得 API 响应

php - iOS推送通知: Not getting any push when sending this payload

即使具有广泛开放的权限,PHP fopen() 也会在文件上失败

linux - perl 不在 cron 中执行

php - 使用 PHP 在 CSS 文件中生成部分背景 URL

html - Javascript/php 轮播无法正常工作

c# - Process.Start 用户名 'Everyone' ?

linux - 无法使用 golang 执行 sh 脚本 - 权限被拒绝

接收 cron 字符串并返回下一次运行时间戳的 PHP 函数

linux - 定时任务错误: "/tmp/crontab.calJpk":5: bad day-of-month