如何使用Laravel 5.1时间表?

时间:2015-11-30 06:35:17

标签: php laravel cron laravel-5.1 cron-task

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

0x20000100

这是我的Kernal.php文件

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 &

和我的命令

<?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();
}
}

在MAMP中测试,通过终端手动执行<?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 ); } } 进行测试。

我不知道如何解决这个问题或者最近发生了什么?

1 个答案:

答案 0 :(得分:1)

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

<?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

它的查找不能查找。