如何使用Laravel 5.1排程?

How to use Laravel 5.1 schedule?

我正在尝试使用 laravel 5.1 scheduler 到 运行 从 Twitter 抓取数据的命令并将其存储在数据库中。如果我将实际命令放在 Kernel.php 文件中,它 运行 不用担心 gets/inserts 数据进入数据库但是当我尝试将它放入外部文件时 运行然后将命令放入内核我得到这个

Running scheduled command: (touch/storage/framework/schedule-4ff51352255727a7381f73c7bd3eb90c; '/Applications/MAMP/bin/php/php5.5.18/bin/php' 'artisan' lookup; rm /storage/framework/schedule-4ff51352255727a7381f73c7bd3eb90c) > /dev/null 2>&1 &

这是我的 Kernal.php 文件

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use DB;
use Session;
use Carbon\Carbon;
use Thujohn\Twitter\Facades\Twitter;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
protected $commands = [
    \App\Console\Commands\Inspire::class,
    \App\Console\Commands\Scheduled_post::class,
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('lookup')
             ->everyMinute()
             ->withoutOverlapping();
}
}

和我的命令

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;

class Lookup extends Command
{
/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'Lookup';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Performing user lookup';

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $user_lookup = Twitter::getUsersLookup(['screen_name' => 'some_user', 'format' => 'object']);
        $social_user = array(
            'email'                     => null,
            'screen_name'               => $user_lookup[0]->screen_name,
        );
        DB::table('social_users')->insert( $social_user );
}
}

在MAMP中测试,通过终端手动执行php artisan schedule:run进行测试。

我不确定如何解决这个问题或发生了什么事?

好的,在您的内核中,使用正确的签名,并将命令添加到您的 :

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use DB;
use Session;
use Carbon\Carbon;
use Thujohn\Twitter\Facades\Twitter;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
protected $commands = [
    \App\Console\Commands\Inspire::class,
    \App\Console\Commands\Scheduled_post::class,
    \App\Console\Commands\Lookup::class,
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('Lookup')
             ->everyMinute()
             ->withoutOverlapping();
}
}
It

是 Lookup 不是 lookup。