简体   繁体   English

Cron 作业在 cpanel 中无法正常工作

[英]Cron job is not working properly in cpanel

I have setup cron job, it is working properly, however when i directly runs the php file(from the path/url) it successfully runs, but from cron its not.我已经设置了 cron 作业,它工作正常,但是当我直接运行 php 文件(从路径/url)时,它成功运行,但从 cron 运行却没有。 However i set another very simple file to make sure my cron command/path is set correctly i created another file and used simple php mail function and its is running successfully.但是,我设置了另一个非常简单的文件以确保我的 cron 命令/路径设置正确,我创建了另一个文件并使用了简单的 php 邮件功能,并且它运行成功。 Kindly suggest me the possible areas to look into it.请建议我研究它的可能领域。 (I am using Cpanel) (我正在使用 Cpanel)

Instead of putting in cronjob command like而不是像这样放入 cronjob 命令

php -f /path_to_script/script.php 

put command like this:像这样放置命令:

curl http://domain.com/yourscript.php

if you want to suppress output you can add > /dev/null at the end.如果你想抑制输出,你可以在最后添加> /dev/null

So full command would be:所以完整的命令是:

curl http://domain.com/yourscript.php > /dev/null

Hope this helps!希望这可以帮助!

As alternative to cURL, you can call your script through text-based browser.作为 cURL 的替代方法,您可以通过基于文本的浏览器调用您的脚本。 Something like this:像这样的东西:

lynx -dump http://localhost/script.php

You shouldn't have any relative paths -- this includes both files and commands .你不应该有任何相对路径——这包括文件和命令 For example, you shouldn't call just cp if you want to copy a file, but something like /bin/cp with the full path to the command.例如,如果你想复制一个文件,你不应该只调用cp ,而应该调用/bin/cp之类的命令的完整路径 To find out the full path, you can run which <cmd> at the command line.要找出完整路径,您可以在命令行运行which <cmd>

I have faced the same problem.我遇到了同样的问题。 I am using task scheduling in laravel project on cpanel.我在 cpanel 上的 laravel 项目中使用任务调度。 My command was我的命令是

/usr/local/bin/php /home/user_name/public_html/path/to/cron/script

It is a version issue.是版本问题。 My server default php version is 7.1.33 but in my project the php version is 7.2.我的服务器默认 php 版本是 7.1.33,但在我的项目中,php 版本是 7.2。 So, when i run the schedule command it takes the php7.1 which is not compatible with my projecct.因此,当我运行 schedule 命令时,它会使用与我的项目不兼容的 php7.1。 So, according to cpanel documentaions the command is actually for different php version因此,根据 cpanel 文档,该命令实际上适用于不同的 php 版本

/usr/local/bin/ea-php99 /home/shadhinapp/domain_path/path/to/cron/script . /usr/local/bin/ea-php99 /home/shadhinapp/domain_path/path/to/cron/script

Any my cron job command is:我的任何 cron 作业命令是:

/usr/local/bin/ea-php72 /home/user_name/path_to_your_project/artisan schedule:run >> /dev/null 2>&1

curl http://mydomain/auto_push/task.php?p=1

This is live working code from my project.这是我项目中的实时工作代码。 See the image below:见下图:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM