php 如何运行 artisan 命令 schedule:run 在托管服务器上?(Laravel)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32283517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run artisan command schedule:run on hosting server? (Laravel)
提问by Inspire Shahin
I have statusUpdate.php file in the xampp\htdocs\project\app\Console\Commands folder.
我在 xampp\htdocs\project\app\Console\Commands 文件夹中有 statusUpdate.php 文件。
statusUpdate.php :
状态更新.php :
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class statusUpdate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'status:update';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update Job status daily';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$affected = DB::table('jobs')->update(array('status' => 1));
}
}
It is created by the following Laravel official documentation.
Then I was added \App\Console\Commands\statusUpdate::class,
class in Kernel.php on xampp\htdocs\project\app\Console folder.
它是由以下 Laravel 官方文档创建的。然后我\App\Console\Commands\statusUpdate::class,
在 xampp\htdocs\project\app\Console 文件夹上的 Kernel.php中添加了类。
Here is the karnel.php file code:
这是 karnel.php 文件代码:
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\App\Console\Commands\statusUpdate::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('status:update')
->everyFiveMinutes();
}
}
Then I was run
然后我被跑了
php artisan schedule:run command using CMD on windows 7.
php artisan schedule: 在 Windows 7 上使用 CMD 运行命令。
Now it is working fine(in local server). My jobs table status field is updated properly by 1.
现在它工作正常(在本地服务器中)。我的工作表状态字段正确更新为 1。
But when I was deployed this project on the shared hosting and added a CRON command for my server in cPanel:
但是当我在共享主机上部署这个项目并在 cPanel 中为我的服务器添加一个 CRON 命令时:
Cron job command is like this : php /path/to/artisan schedule:run 1>> /dev/null 2>&1
Cron 作业命令是这样的: php /path/to/artisan schedule:run 1>> /dev/null 2>&1
Now in this case command not working & this is the problem. how can I solve it?
现在在这种情况下命令不起作用&这就是问题所在。我该如何解决?
采纳答案by Aditya Giri
Well. I am giving you the answer as per what you have said.
好。我按照你说的给你答复。
Cron job command is like this :
php /path/to/artisan schedule:run 1>> /dev/null 2>&1
Cron 作业命令是这样的:
php /path/to/artisan schedule:run 1>> /dev/null 2>&1
The path should be locating the artisan file in the server. Like this:
路径应该是在服务器中定位 artisan 文件。像这样:
Let's say your artisan file location is /var/www/artisan
, then the simple answer could be do like this:
假设您的工匠文件位置是/var/www/artisan
,那么简单的答案可以是这样:
php /var/www/artisan schedule:run 1>> /dev/null 2>&1
php /var/www/artisan schedule:run 1>> /dev/null 2>&1
Just check if that works. Thank You!
只要检查它是否有效。谢谢你!
UPDATE:
更新:
This is how it should look like.
这就是它的样子。
回答by Seunope
This worked fine for me
这对我来说很好用
/usr/local/bin/php /path/to/artisan schedule:run >> /dev/null 2>&1
回答by N?s????? ?
You should add the command from the cPanel server as
您应该将来自 cPanel 服务器的命令添加为
/usr/local/bin/php /home/xyz/public_html/artisan schedule:run 1>> /home/xyz/public_html/log_laravel 2>&1
This will keep all the logs in /home/xyz/public_html/log_laravel
这将保留所有日志 /home/xyz/public_html/log_laravel
Running scheduled command: '/opt/cpanel/ea-php71/root/usr/bin/php' 'artisan' SyncAPIOrders:orders > '/dev/null' 2>&1
In my case cron Job was not working, if you are about to schedule the command as once a day (i.e., 00:00) iff, same time is notreflected in a $schedule->command();
object
在我的情况下,cron Job 不起作用,如果您打算将命令安排为每天一次(即 00:00)iff,则同一时间不会反映在$schedule->command();
对象中
If the commands were incorrect, I used to get this warning in my Email as
如果命令不正确,我曾经在我的电子邮件中收到此警告
PHP Warning: Module 'magickwand' already loaded in Unknown on line 0
Status: 404 Not Found
X-Powered-By: PHP/5.6.37
Content-type: text/html; charset=UTF-8
No input file specified.
In Kernel.php
you should specify
在Kernel.php
你应该指定
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('SyncAPIOrders:orders')
->timezone('Asia/Kolkata')
->dailyAt('00:00');
}