Laravel task scheduling on shared hosting doesn't work - php

I have a laravel app and it runs on a shared hosting. I defined a cronJob on cpanel and a job on laravel app but it doesn't work.
app/console/kernel.php:
protected $commands = [
'\App\Console\Commands\CronJob',
];
protected function schedule(Schedule $schedule)
{
$schedule->command('CronJob:test')
->everyMinute();
}
app/console/comands/mycronjob:
public function handle()
{
\App\Model::create([
'name'=> 'foo',
...
]);
}
and on server the cronjob is:
php /path/to/artisan schedule:run >> /dev/null 2>&1
when I test it locally by command php artisan Cronjob:test it works and creates the model but it doesn't work on server. can you tell what's the problem? Thanks.

Related

Laravel console command trait method not found

I have a Laravel project that has been deployed with Forge and had OPCache enabled using Forge. I noticed last week that when I pushed some changes, the changes that were in the views and in the controllers were present on the server, but custom artisan commands that I run don't recognize updates.
Put another way, updates to the blades are showing on the screen. Updates that I have added to the controllers are changing the way information is passed to the blade files, but I have a custom artisan command that runs a series of methods in a trait. The actual file on the server shows the new method that I pushed, but when I run the artisan command in the CLI, it says that the method cannot be found.
I have stopped, restarted, and reloaded OPCache countless times. I have restarted Nginx. I have disabled OPCache and restarted PHP. It is still saying that the method is not found. Does anyone have any ideas?
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Traits\FTPImportsTrait;
class CheckFTPImports extends Command
{
use FTPImportsTrait;
protected $signature = 'checkForImports';
protected $description = 'Check for imports...';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$this->checkBankImports();
}
}
-----------
<?php
namespace App\Traits;
trait FTPImportsTrait;
{
public function checkBankImports()
{
dd('YOU ARE NOT CRAZY');
}
}
$ php artisan checkForImports
$ method checkBankImports does not exist.
UPDATE:
It has to be some sort of configuration issue on the server. I just deployed the project to a fresh DO droplet and the command works as expected.
It only happened in the production environment for me.
Running:
php artisan clear-compiled
deleted the cached version and solved my issue.
Thanks a ton to #num8er.

i could not run artisan schedule:run cron command at shared hosting

I want to achieve task scheduling in my laravel 5.8 project. For that, I have created a custom artisan command artisan send: credentials which send emails to specific users based on their status.
sendUserCredentials.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Mail\credentialsEmail;
use App\Models\userModel;
use Mail;
class sendUserCredentials extends Command
{
protected $signature = 'send:credentials';
protected $description = 'Credentials send Successfully!';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$users = userModel::select(["email","username","role","id"])->where("credentials","NO")->get();
foreach ($users as $key => $user) {
Mail::to($user->email)->send(new credentialsEmail($user));
userModel::where("id",$user->id)->update(["credentials"=>"SEND"]);
}
}
}
I added this command in kernel.php so that I can run this command using the laravel task scheduler.
kernel.php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
Commands\sendUserCredentials::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('send:credentials')
->everyMinute();
}
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
so on my local server, everything works like a charm when I run this command php artisan schedule:run
but on the shared server when I run scheduler using the cron command *****/path/to/project/artisan schedule:run >> /dev/null 2>&1 it gives me an error like this
local.ERROR: The Process class relies on proc_open, which is not available on your PHP installation. {"exception":"[object] (Symfony\\Component\\Process\\Exception\\LogicException(code: 0): The Process class relies on proc_open, which is not available on your PHP installation. at /path/to/vendor/vendor/symfony/process/Process.php:143)
BUT when I run the artisan command directly *****/path/to/project/artisan send:credentials >> /dev/null 2>&1 using the cron job then there is no error and emails send successfully!
I am using laravel 5.8 and deployed my website on namecheap shared hosting. Following command help me to execute cron job properly:
*/5 * * * * /usr/local/bin/php /home/YOUR_USER/public_html/artisan schedule:run >> /home/YOUR_USER/public_html/cronjobs.txt
As namecheap allow minimum of 5 min interval, so above command will execute after 5 min and output will be displayed in a text file.
The Error
The Process class relies on proc_open, which is not available on your PHP installation.
is because of Flare error reporting service enabled in debug mode. To solve this please follow the steps shared below.
Add the File /config/flare.php and add the below content
'reporting' => [
'anonymize_ips' => true,
'collect_git_information' => false,
'report_queries' => true,
'maximum_number_of_collected_queries' => 200,
'report_query_bindings' => true,
'report_view_data' => true,
],
And Clear the Bootstrap cache with below command
php artisan cache:clear && php artisan config:clear
Most probably the issue will be solved. Otherwise check once this link

Laravel doesn't find command

I make
php artisan make:command BackupDatabaseCommand --command="command:backupdb"
I also registered firmly
app\Console\kernel.php
protected $commands = [
\App\Console\Commands\BackupDatabaseCommand::class,
];
But even if you try to execute the command i get here
The system cannot find the path specified.
I want to know how to solve it
Your path is wrong Since you are already in App\Console directory there is no need to specify App\Console it should be this:
protected $commands = [
Commands\BackupDatabaseCommand::class,
];
here is the image from my working project
Thanks
To Create command
php artisan make:command BackupDatabaseCommand --command=command:backupdb
You can register command as:
protected $commands = [
'App\Console\Commands\BackupDatabaseCommand'
];
and you can run command using:
php artisan command:backupdb

Laravel Queue Driver not calling handle() on jobs, but queue:listen daemon is logging jobs as processed

I've taken over a Laravel 5.2 project where handle() was being called successfully with the sync queue driver.
I need a driver that supports dispatch(..)->delay(..) and have attempted to configure both database and beanstalkd, with numerous variations, unsuccessfully - handle() is no longer getting called.
Current setup
I am using Forge for server management and have set up a daemon, which is automatically kept running by Supervisor, for this command:
php /home/forge/my.domain.com/envoyer/current/artisan queue:listen --sleep=3 --tries=3
I've also tried queue:work, naming 'database/beanstalkd', with and without specifying --sleep, --tries , --deamon
I have an active beanstalkd worker running on forge.
I have set the default driver to beanstalkd in \config\queue.php and QUEUE_DRIVER=beanstalkd in my .env from within Envoyer, which has worked fine for other environment variables.
After build deployment Envoyer runs the following commands successfully:
php artisan config:clear
php artisan migrate
php artisan cache:clear
php artisan queue:restart
Debug information
My queue:listen daemon produces log within .forge says it processed a job!
[2017-07-04 08:59:13] Processed: App\Jobs\GenerateRailwayReport
Where that job class is defined like this:
class GenerateRailwayReport extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $task_id;
public function __construct($task_id)
{
$this->task_id = $task_id;
clock("GenerateRailwayReport constructed"); // Logs Fine
}
public function handle()
{
clock("Handling Generation of railway report"); // Never Logs
//Bunch of stuff all commented out during my testing
}
public function failed(Exception $e)
{
clock("Task failed with exception:"); // Never Logs
clock($e);
}
}
My beanstalkd worker log within .forge has no output in it.
Nothing in my failed_jobs table.
-Really, really appreciate any help at this point!

Laravel custom command not working

I made a new command with:
php artisan make:console CrawlData
Then I changed two variables:
protected $signature = 'make:crawl';
protected $description = 'My crawling command';
The problem is that when I run:
php artisan make:crawl
It outputs:
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "make:crawl" is not defined.
You also need to register the command in the App\Console\Kernel class for it to be recognized:
protected $commands = [
...
\App\Console\Commands\CrawlData::class,
];
You can read more about that in the Registering Commands documentation.
Starting with Laravel 5.5 commands in app/Console/Commands are automatically registered.

Categories