简体   繁体   English

Laravel schedule:run 在添加到 cron 作业时不起作用

[英]Laravel schedule:run is not working when added into the cron job

I have made a command and scheduled it for every 30 minutes.我已经制定了一个命令并安排每 30 分钟执行一次。 When I run php artisan schedule:run it works perfectly fine and returns with the expected results, but when I configured it on my live server my cron job do run but instead of retuning the success message it returns with list of all available command in my laravel project.当我运行php artisan schedule:run它工作得很好并返回预期结果,但是当我在我的实时服务器上配置它时,我的 cron 作业确实运行但它没有重新调整成功消息,而是返回了我的所有可用命令的列表laravel项目。 Here is what I am doing.这就是我在做什么。

Command Kernel:命令 Kernel:

$schedule->command('update:callLogs')
            ->everyMinute();

Cron Entry: Cron 条目:

/usr/bin/php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run

And this is the response I am getting这就是我得到的回应

Laravel Framework 5.8.38 Laravel 框架 5.8.38

Usage:
command [options] [arguments]

Options:
 -h, --help            Display this help message
 -q, --quiet           Do not output any message
 -V, --version         Display this application version
  --ansi            Force ANSI output
  --no-ansi         Disable ANSI output
 -n, --no-interaction  Do not ask any interactive question
  --env[=ENV]       The environment the command should run under
 -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
 (List of all availabe commands)

Any help will be much appreciated.任何帮助都感激不尽。

EDIT Now my command looks like this编辑现在我的命令看起来像这样

* * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm && php artisan update:callLogs

but getting the same response whereas when I copy the same command and using putty ran the same command and it works perfectly fine.但是得到相同的响应,而当我复制相同的命令并使用腻子运行相同的命令并且它工作得很好。 Now it's been a week now and I'm still stuck at this cron thing.现在已经一周了,我仍然停留在这个 cron 上。

I fixed this by specifying the path to PHP instead of using just php .我通过指定 PHP 的路径而不是仅使用php来修复此问题。

From this: cd /home/foobar && php artisan schedule:run从这个: cd /home/foobar && php artisan schedule:run

To this: cd /home/foobar && /usr/local/bin/php artisan schedule:run为此: cd /home/foobar && /usr/local/bin/php artisan schedule:run

This stopped me from getting a list of available artisan commands and gave me the right output.这使我无法获得可用工匠命令的列表,并给了我正确的 output。

I can see it looks like you've already tried that, but I think others will run into this too.我看得出您已经尝试过了,但我认为其他人也会遇到这种情况。 I'd imagine your issue is something to do with the PHP version you're using not being able to properly run PHP scripts.我想您的问题与您使用的 PHP 版本有关,无法正确运行 PHP 脚本。 Maybe an opcache thing with CLI?也许是 CLI 的 opcache 东西?

I faced big challenge as well when I was deploying one my applications, and finally managed to tackle it with:当我部署我的一个应用程序时,我也面临着巨大的挑战,并最终设法解决了这个问题:

cd /path-to-project && /opt/cpanel/ea-php71/root/opt/cpanel/ea-php74/root/usr/bin/php-cgi artisan schedule:run

I use Laravel 5.7 for my application我的应用程序使用 Laravel 5.7

You could try the following code:你可以试试下面的代码:

* * * * * php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1

>> /dev/null 2>&1 : we will discard all output of a command. >> /dev/null 2>&1 :我们将丢弃命令的所有 output。

Can you try the below in cron and share the output of crontab.out您可以在 cron 中尝试以下操作并共享 crontab.out 的 output

* * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/ && php artisan schedule:run >> crontab.out 2>&1
*/30 * * * * php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1

OR要么

*/30 * * * * /usr/bin/php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1

OR要么

*/30 * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm && php artisan schedule:run >> /dev/null 2>&1

Also read full post: https://devnote.in/how-to-set-auto-database-backup-with-cron-scheduler-in-laravel/另请阅读完整帖子: https://devnote.in/how-to-set-auto-database-backup-with-cron-scheduler-in-laravel/

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

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