PHP cron 通过 php 检测?
有没有办法查明 Cron Jobs 在服务器上是否可用? 我的意思是我想在 PHP 脚本中检测到这一点。
Is there a way to find out if Cron Jobs are available on the server?
I mean I want to detect this in a PHP script..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须使用
system()
来可靠地确定:You would have to use
system()
to determine that reliably:请记住,这一切都与 Linux 系统上的权限有关,因此如果您使用的用户没有读取该文件的权限,您应该会收到“文件/目录不存在或未找到”错误。< /em>
所以我的猜测是,除非你以 root 身份运行它或者向需要读取 cron 的用户授予权限,否则你会遇到问题。
您可以在 cron 目录中查找 cron 文件
在 Cent OS 5 服务器上,这里的 cron 目录 id:
您也可以在该目录中拥有多个 cron。
您可以解析/读取该文件以查看 cron 中配置了哪些脚本。
Just remember it's all about permissions on a Linux system, so if the user you're using doesn't have permission to read the file you should get a "File/directory doesn't exists or not found" error.
So my guess is unless you're running this as root or give permission to the user that needs to read cron, you will run into problems.
You could just look for cron files in the cron directory
On a Cent OS 5 server the cron directory id here:
you can have multiple crons in the directory as well.
You could parse/read the file to see what scripts are configured in cron as well.