Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么Cron调度器不能在laravel中工作?_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 为什么Cron调度器不能在laravel中工作?

Php 为什么Cron调度器不能在laravel中工作?,php,laravel,laravel-5,Php,Laravel,Laravel 5,注意:我正在使用laravel 5.0 我已经执行了这个常见的“***php/path/to/artisan schedule:run>>/dev/null 2>&1”,就像在laravel的文档中提到的那样,但是cron仍然无法使用我的内核文件: <?php namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as Cons

注意:我正在使用laravel 5.0

我已经执行了这个常见的“***php/path/to/artisan schedule:run>>/dev/null 2>&1”,就像在laravel的文档中提到的那样,但是cron仍然无法使用我的内核文件:

<?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\InstagramAutopost',
];

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

您的
InstagramAutopost.php
(如上所示)不是有效的
命令

该类需要扩展
Command
not
Controller
,并实现
handle()
方法以及一些其他必需的属性


您可以使用
php artisan make:command
创建一个适当命令的shell,然后将粘贴复制到其中。

如果在cron之外运行,代码是否有效?你的cron日志怎么说?你使用Instagram的私有API破坏了Instagram的条款,所以可能他们只是阻止了你。我测试了它,并且它与控制器一起工作良好。如果你通过命令行手动运行
php/path/to/artisan schedule:run
,它能工作吗?我没有访问SSH的权限,但负责人告诉我启用了cron。因此,当我将脚本从控制器移动到命令不起作用时,如果您没有访问权限,则应要求负责人进行调试。如果你自己没有解决问题的基本权限,我们就无能为力。这只是个错误,我复制了错误的代码。对不起。现在我编辑了代码,请告诉我,像你一样,我曾经使用函数handle()和get_main_photo(),是否可以将一个函数与handle()函数一起使用,或者在这个文件中,我应该只使用handle函数?代码看起来不错。是的,您可以从
handle()
调用其他函数。很遗憾,您必须与运行服务器的人员一起解决此问题。非常感谢我发现了问题,是配置文件夹中的一个文件使artisan无法工作,我认为此文件包含url帮助程序,正如我们所知,在配置文件中使用url帮助程序会使artisan无法工作。
use App\Export;
use App\Insta;
use Auth;
use Response;
use App\Vehicle;
use View;
use Instagram;
use App\Libraries\UserPreferences;
use Illuminate\Console\Command;
use App\Libraries\Info;
use Validator;
use Illuminate\Support\Facades\URL;

class InstagramAutopost extends Command {

 /**
 * The console command name.
 *
 * @var string
 */
protected $name = 'instagramautopost';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Instagram Autopost';

/**
 * Execute the console command.
 *
 * @return mixed
 */

 public function handle() {

    $vehicles_id = Vehicle::where(['user_id' => Auth::id()])->get();
    $numVehicles = count($vehicles_id);

    for ($i=0; $i < $numVehicles ; $i++) {
        $vExport = Export::where(['v_id' => $vehicles_id[$i]['id']])->first();

        if (!$vExport || ($vehicles_id[$i]['last_modified'] > $vExport['instagram_date'])) {
            $settings = \App\Insta::where(['user_id' => Auth::id()])->first();
            if($settings){
                $vInfo = Vehicle::where(['id' => $vehicles_id[$i]['id']])->first();

                $img = $this->get_main_photo($vInfo['photos'], 400, 300, V12_IMAGES_URL . '/' . Auth::user()->photos_directory . '/' . $vInfo['id'] . "/");
                if($img && getimagesize($img) ){

                    $price = ($vInfo['internet_specials']=='yes' and $vInfo['featured_price']!=0)?$vInfo['featured_price']:$vInfo['price'];
                    $msg = $vInfo['year'].' '.$vInfo['make_name'].' '.$vInfo['model'].' $'.$price;

                    /////// CONFIG ///////
                    $username = $settings->username;
                    $password = $settings->password;

                    $debug = false;
                    $photo = $img ;
                    $info  = new Info(Auth::id(), $vehicles_id[$i]['id']);
                    $caption = $msg.' '.$info->getDomain() . "/inventory/view/" . $vehicles_id[$i]['id'];    

                    $instagrame = new Instagram($username, $password, $debug);

                    //Login
                    try {
                        $instagrame->login();

                    } catch (InstagramException $e) {
                        exit();
                    }

                    //Upload photo
                    try {

                        $instagrame->uploadPhoto($img, $caption);

                        //update exports
                        $exp = Export::where(['v_id' => $vehicles_id[$i]['id']])->first();
                        if(!$exp){
                            $exp = new Export;
                            $exp->v_id = $vehicles_id[$i]['id'];
                        }
                        $exp->instagram = 'yes';
                        $exp->instagram_date = date('Y-m-d H:i:s');
                        $exp->save();


                    } catch (Exception $e) {

                    }   
                }

            }
        }
    }
}

/**
* Get the main photo of a vehicle
*
* @return Response
*/
public function get_main_photo($photos, $width, $height, $path = '') {
    if ($photos != '') {
        $ar_photos = unserialize($photos);
        for ($i = 0; $i < count($ar_photos); $i++) {
            if ($ar_photos[$i]['main'] == 'yes') {
                return (empty($width) ? $path . $ar_photos[$i]['photo'] : $path . str_ireplace('.jpg', '_' . $width . $height . '.jpg', $ar_photos[$i]['photo']));
            }
        }
    }
    return '';
    }

 }