Cron job doesn't work, Laravel and cPanel - php

For some reason I no longer understand my cron does not work, when I execute the command schedule: run changes are made, however on the server nothing happens, I will explain each step to see if anyone can tell me that I can be doing wrong
this is the code of my command
<?php
namespace App\Console\Commands;
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Plan;
use App\Plan_negocio2;
use App\Plan_negocio;
use App\Pagina;
use DateTime;
use Illuminate\Console\Command;
//use Illuminate\Foundation\Inspiring;
class Resaltador extends Command {
/**
* The console command name.
*
* #var string
*/
protected $name = 'res:resaltado';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Verificar Resaltador';
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$plan=Plan_negocio::all();
//$fechaAct=$request->fecha;
if ($plan)
{
$arrNegocio=[];
foreach ($plan as $key => $value)
{
//$value->fechafin=strtotime("2017-04-07")-time();
date_default_timezone_set('America/Caracas');
$date = new DateTime($value->fechafin);
$dateHoy=new DateTime();
//$dat=$dateHoy->getTimestamp();
$dat=9999999999999999;
$value->fechafin=$date->getTimestamp();
//$now = new DateTime();
//$gene= $date1->format('U') - $now->format('U');
if ($dat>$value->fechafin)
{
$negoPlan=Pagina::find($value->negocio_id);
$negoPlan->resalta_id=1;
$res=$negoPlan->save();
}
}
}
}
}
this, the code of the kernel
<?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\Inspire',
\App\Console\Commands\Resaltador::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
/*$schedule->command('inspire')
->hourly();*/
$schedule->command('res:resaltado')->everyMinute();
}
}
When I execute the schedule: run command everything is fine
But as I say, when I try to activate it from the server I do not understand that it can be wrong, I leave the steps
In the folder 'loupper' is where I have stored laravel, with putty I get the path and assign it to the cron jobs manager in cpanel
I don't have composer on the server, but investigating I read that it is not necessary,However nothing happens, what can I be doing wrong?
UPDATE:
I just checked and this email has arrived
/usr/local/cpanel/bin/jailshell: php/home3/pixsony6/public_html/loupper.com/loupper/artisan: No such file or directory

You are missing a space between php and the path in cPanel

Related

while run cron with lumen : There are no commands defined in the "insert" namespace.

I have written code for cron command as below in lumen (micro framwork of laravel)
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\EmailDump;
use DB;
/**
* dumpEmails Class
*
* This cron is to dump emails with cron use
*
* #author Hetal Gohel <hetal.gohel#brainvire.com>
*
*/
class dumpEmails extends Command {
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'insert:emails';
/**
* The console command description.
*
* #var string
*/
protected $description = 'This cron is to dump emails with cron use';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
echo "1";die;
}
}
in kernel file defined as below,
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
\Laravelista\LumenVendorPublish\VendorPublishCommand::class,
'\App\Console\Commands\dumpEmails',
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
// protected function schedule(Schedule $schedule)
// {
// return $schedule;
// }
}
I have fired command from console as below,
php artisan insert:emails
while run this command getting error as below,
[Symfony\Component\Console\Exception\CommandNotFoundException] ←[39;49m
←[37;41m There are no commands defined in the "insert" namespace.
please help me to resolve this issue.thank you.
Please remove __construct and keep just the handle method.
Also, when you are listing under $commands at Kernel you need to specify the class.
So your
`\App\Console\Commands\dumpEmails`
becomes
DumpEmails::class
A few extra tips:
Class names are capitalised; (dumpEmails -> DumpEmails)
Add the { to a new line;
This
class dumpEmails extends Command {
should be
class DumpEmails extends Command
{
I also recommend checking out about PSR-x standards. I left one of the blogs I think might help you kick start with them, but go further! :)
Last, but not least, do not forget Command Parent already lets you use its command line potential. So if you wish to output and debug, you can do so by using:
$this->info('Your message to inform');
$this->error('Your error message');

Laravel not registering a new command

I am using laravel 5.5 and trying to create a new command. This has worked well in 5.4 but now it won't register at all.
First I create the command:
php artisan make:command heloworl
And I get something like this:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class heloworl extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'Hello:World';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
echo "hello world";
}
}
Now I try php artisan hello:world and it says that the command does not exist at all.
I also tried just php artisan to get a list of commands and it is not there.
Any ideas?
I had a Laravel 5.2 project that I upgraded to 5.5, and for me it wasn't loading them automatically for some reason, even though I had the command classes in the right place.
Turns out I had to modify app/Console/Kernel.php, adding the following line to the top of the commands method:
$this->load(__DIR__.'/Commands');
After this I was able to use my commands properly, and I didn't have to add each of them to the $commands array.
You need to add it to app\Console\Kernel.php to the protected $commands array.
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands
= [
//fully qualified namespace to class goes here
];
}

Laravel 5.3 scheduler doesn't run automatically

I'm using Laravel 5.3.26 and cannot set the scheduler to run automatically although i have the cron job ready.
I' ve created a new command ligmena:update, below is the code:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class ligmena extends Command {
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'ligmena:update';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Update';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle() {
//
$today = strtotime("now");
$energa_symvolaia = DB::table('symvolaia')->where('eidos_kinisis', '1')->get();
foreach ($energa_symvolaia as $es) {
$imerominia_lixis = strtotime(str_replace("/", "-", $es->imerominia_lixis));
if ($today > $imerominia_lixis)
DB::table('symvolaia')->where('id', '<', $es->id)->update(['eidos_kinisis' => '4']);
}
}
}
?>
Below is the code of Kernel.php
<?php
namespace App\Console;
use DB;
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\ligmena::class,
//
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule) {
// $schedule->command('inspire')
// ->hourly();
$schedule->command('ligmena:update')->everyMinute();
}
/**
* Register the Closure based commands for the application.
*
* #return void
*/
protected function commands() {
require base_path('routes/console.php');
}
}
?>
I've setup the cron job like this:
php /home/site.com/public_html/testdemo/artisan schedule:run >> /dev/null 2>&1
and it runs every minute.
If I run the command manually it works fine.
Any suggestions?
I 've solved the issue using raw mysql.
The cron job was running fine and the code was ok but it was not changing the DB.
After i changed to raw mysql it worked fine

Artisan Console command not working in 5.1

I am new in laravel. I was trying to make a custom artisan command for creating tables in my test project.I followed this link but my command was not on the artisan list.Event I tried same example given in that link but its also not worked. I dont know why its happening.
I DID THIS:
1) Run this command php artisan make:console SendEmails
2) Put complete class code in app/Console/Commands/SendEmails.php file
<?php
namespace App\Console\Commands;
use App\User;
use App\DripEmailer;
use Illuminate\Console\Command;
class SendEmails extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'email:send {user}';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Send drip e-mails to a user';
/**
* The drip e-mail service.
*
* #var DripEmailer
*/
protected $drip;
/**
* Create a new command instance.
*
* #param DripEmailer $drip
* #return void
*/
public function __construct(DripEmailer $drip)
{
parent::__construct();
$this->drip = $drip;
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$this->drip->send(User::find($this->argument('user')));
}
}
Please help me let me know what I am doing wrong.
You just forgot to Register your command.
This part: https://laravel.com/docs/5.1/artisan#registering-commands.
Open app/Console/Kernel.php and add you command class in $commands array.
like this :
protected $commands = [
Commands\SendEmails::class
];
That's it.

laravel 5 schedule works with ->cron('* */1 * * *') but doesn't work with ->hourly()

I create a command conttroller, this is my code
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Http\Controllers\AppController;
class UpdData extends Command {
protected $name = 'upd:data';
protected $description = 'Update data';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the command.
*
* #return void
*/
public function handle()
{
$app = new AppController;
$this->info("updated!");
$app->update_data();
}
}
This is my crontab
#!/bin/bash
PATH=/usr/bin
* * * * * php /home/ubuntu/workspace/app/artisan schedule:run 1>> /dev/null 2>&1
My Kernel.php file
<?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\Inspire',
'App\Console\Commands\UpdData',
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('upd:data')->hourly(); // case 1
$schedule->command('upd:data')->cron('* */1 * * *'); // case 2
}
}
On the case 1, I try to php artisan schedule:run, I get No scheduled commands are ready to run. message. On the case 2 it work, but I need to command by myself. But the two case doesn't not auto run it. I build my platform on the cloud9, I need your help thanks!
I don't find the reason, but this code is work for me, if I find the real reason, I will update my answer.
This is work for me, replace hourly with cron.
protected function schedule(Schedule $schedule)
{
$schedule->command('upd:data')->cron('0 * * * *');
}

Categories