自定义 Laravel Artisan 命令无法通过 cron 作业使用
当我通过 SSH 连接时,我有自定义的 Artisan 命令可以在本地和我的生产服务器上运行,但不能用于任何 cron 作业.我什至尝试以运行 cron 作业的用户身份运行它,并且在我的控制台上运行良好.
I have custom Artisan commands that run locally as well as on my production server when I am SSH'd in, but are unavailable to any cron jobs. I've even tried running it as the user the cron job runs as and it works fine from my console.
当我在上述设置中运行 php artisan
时,我的自定义命令会列出并可用.但是,当我将 php artisan
作为 cron 作业运行时,它们并未列出.
When I run php artisan
in the above settings, my custom commands are listed and available. However, they are not listed when I run php artisan
as a cron job.
此外,尝试将自定义命令 php artisan subject:calculate
作为 cron 作业运行会导致以下错误:
Furthermore, trying to run the custom command php artisan subjects:calculate
as a cron job results in the following error:
<代码>[无效参数异常]
subjects"命名空间中没有定义命令.
推荐答案
我遇到了同样的错误,但我找到了解决方案.第一次尝试失败
I was fighting with the same error and I found the solution. First failed attempts
*/5 * * * * /usr/bin/php /home/mysite/public_html/artisan my:command
*/5 * * * * php /home/mysite/public_html/artisan my:command
解决方案
*/5 * * * * /usr/local/bin/php /home/mysite/public_html/artisan my:command
相关文章