Php 如何运行artisan命令计划:在托管服务器上运行?(拉雷维尔)
我在中有statusUpdate.php文件 xampp\htdocs\project\app\Console\Commands文件夹 statusUpdate.php:Php 如何运行artisan命令计划:在托管服务器上运行?(拉雷维尔),php,laravel,cron,cpanel,laravel-5.1,Php,Laravel,Cron,Cpanel,Laravel 5.1,我在中有statusUpdate.php文件 xampp\htdocs\project\app\Console\Commands文件夹 statusUpdate.php: <?php namespace App\Console\Commands; use Illuminate\Console\Command; use DB; class statusUpdate extends Command { /** * The name and signature of t
<?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));
}
}
然后我就跑了
php artisan schedule:在windows 7上使用CMD运行命令
现在它工作正常(在本地服务器中)。“我的作业表状态”字段已由1正确更新
但当我在共享主机上部署此项目并在cPanel中为我的服务器添加CRON命令时:
Cron作业命令如下:php/path/to/artisan schedule:run1>/dev/null 2>&1
现在在这种情况下,命令不起作用&这就是问题所在。我该怎么解决呢?好吧。我正按照你所说的回答你 Cron作业命令如下:
php/path/to/artisan schedule:run1>/dev/null 2>&1
路径应该是在服务器中定位artisan文件。像这样:
假设您的artisan文件位置为/var/www/artisan
,那么简单的答案是:
php/var/www/artisan schedule:run1>/dev/null 2>&1
检查一下是否有效。谢谢大家!
更新:
这就是它应该是什么样子。这对我来说效果很好
/usr/local/bin/php /path/to/artisan schedule:run >> /dev/null 2>&1
您应该将cPanel服务器中的命令添加为
/usr/local/bin/php /home/xyz/public_html/artisan schedule:run 1>> /home/xyz/public_html/log_laravel 2>&1
这将把所有日志保存在/home/xyz/public\u html/log\u laravel
Running scheduled command: '/opt/cpanel/ea-php71/root/usr/bin/php' 'artisan' SyncAPIOrders:orders > '/dev/null' 2>&1
在我的例子中,cron作业不起作用,如果您打算将命令安排为每天一次(即,00:00)iff,则$schedule->command()中反映的时间是not代码>对象
如果命令不正确,我通常会在电子邮件中收到此警告
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.
在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');
}
@michael是的,我添加了我的路径,/home/username/public\u html/projectfolder/artisan schedule:run服务器的配置是什么?告诉操作系统以及您是否已安装CRON@AdityaGiri,服务器配置意味着它是我的共享主机面板。是的,操作系统已经安装了CRON。我在下面给出了答案。检查那些first@AdityGiri,我的命令php/path/to/artisan schedule:run 1>>/dev/null 2>&1与您的命令php/var/www/artisan schedule:run 1>>/dev/null 2>&1有什么不同!我已经在命令中给出了正确的路径。我的命令php/path/to/artisan schedule:run 1>>/dev/null 2>&1与您的命令php/var/www/artisan schedule:run 1>/dev/null 2>&1之间有什么不同!我已经给出了我指挥的正确路径。好吧,两者都是一样的。假设您正在使用Linux环境运行服务器path/to/artisan
表示您正在链接到类似D:\xampp\path\to\artisan
的内容,显然这不是您要查找的内容。您正在链接到一个不存在的文件。如果您更改文件路径,它肯定会起作用。告诉我你的项目根目录路径,我会告诉你应该输入的正确命令。/home/belogin/public_html/jobssite/this my path,我尝试使用这个/home/belogin/public_html/jobssite/artisan schedule:run 1>/dev/null 2>&1,但不起作用。我查看了文档,查询应该是这样的:*****php/home/belogin/public\u html/jobssite/artisan计划:运行1>>/dev/null 2>&1
确定。当我给出*****php/home/belogin/public_html/jobssite/artisan计划时:在命令框中运行1>>/dev/null 2>&1。它显示坏命令不能安装在cron中:(因为我已经给了时间使用另一个选项)。
/**
* 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');
}