My config for queue
config/queue:
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
//'table' => 'jobs',
'table' => 'ncste_jobs',
'queue' => 'default',
'expire' => 60,
],
],
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'ncste_failed_jobs',
],
Konsole/Kernel.php:
protected function schedule(Schedule $schedule)
{
//here som comand
$schedule->command('sudo supervisorctl stop laravel-worker:*')->name('supervisorctl-stop')->everyMinute()->withoutOverlapping();
$schedule->command('sudo supervisorctl start laravel-worker:*')->name('supervisorctl-start')->everyMinute()->withoutOverlapping();
//here some command
}
Cron:
* * * * * /usr/bin/php /var/www/mydomain.com/artisan schedule:run 1>>/dev/null 2>&1
Why do these 2 commands don't work through the cron? If run manually it work.
$schedule->exec('sudo supervisorctl stop laravel-worker:*')->everyMinute()->withoutOverlapping();
$schedule->exec('sudo supervisorctl start laravel-worker:*')->everyMinute()->withoutOverlapping();
Related
I've been having this problem for days and I don't know how to solve it.
I have a job that I'm dispatching from my controller, but once I do php artisan queue:work nothing shows up in my console (not windows, not a Linux terminal emulator like Cmder)
My job:
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\ProfessorSuscription;
use App\Models\ProfessorSuscriptionHistory;
use Carbon\Carbon;
class CheckSuscription implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
}
public function handle()
{
$suscription_history = new ProfessorSuscriptionHistory();
$suscription_history->user_id = 13;
$suscription_history->type = 'trimestral';
$suscription_history->pdf = 'test.pdf';
$suscription_history->ended_at = Carbon::now()->addMonth(3);
$suscription_history->save();
}
}
That is my controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Jobs\CheckSuscription;
class TestController extends Controller
{
public function index()
{
CheckSuscription::dispatchNow();
}
}
Note: when I execute my controller by route, it works perfectly and saves me in the database
My queue config:
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120
After i do php artisan queue:work:
PD: I used commands php artisan queue:table, php artisan cache:clear and php artisan config:clear
PD2: Nothing appears too in my jobs or failed_jobs table.
PD3: Nothing appears in my laravel.log related to my Job.
How can i fix it? I've searched for days and can't find a solution. Thank you.
EDIT: config/queue.php file:
'default' => env('QUEUE_CONNECTION', 'sync'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
'after_commit' => false,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
'block_for' => 0,
'after_commit' => false,
],
'sqs' => [
'driver' => 'sqs',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
'queue' => env('SQS_QUEUE', 'default'),
'suffix' => env('SQS_SUFFIX'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'after_commit' => false,
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
'after_commit' => false,
],
],
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
You should set QUEUE_CONNECTION=database in your env file or to change the config/queue.php default value to database. After that you should use CheckSuscription::dispatch(); instead.
This is my config queue file. the queue is not working when I change
my connection to database. it only works when I use sync but it
doesn't run in the background. How do I make this work in the background? or how do I fix this problem?
<?php
return [
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
'after_commit' => false,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
'block_for' => 0,
'after_commit' => false,
],
'sqs' => [
'driver' => 'sqs',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
'queue' => env('SQS_QUEUE', 'default'),
'suffix' => env('SQS_SUFFIX'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'after_commit' => false,
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
'after_commit' => false,
],
],
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
];
To execute queue run following command:
php artisan queue:work
Please check the setting worker listen to your process.
ps aux | grep php
Set worker listen:
php artisan queue:listen --queue=queu_name --tries=1 --memory=128 --timeout=300
php artisan queue:work - don't work.
ErrorException: Trying to access array offset on value of type null
vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php:156
protected function resolve($name)
{
$config = $this->getConfig($name);
return $this->getConnector($config['driver'])
->connect($config)
->setConnectionName($name);
}
config/queue.php
<?php
return [
'default' => env('QUEUE_CONNECTION', 'sync'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
],
]
];
As already mentioned above, this error can be caused by mis-configurations so try:
check your .env file for the proper QUEUE_CONNECTION.
add the connection name to your work command e.g php artisan queue:work database --queue=queue_name to run on database connection
In my case however, I ran into this error when using supervisor on a production server. The supervisor process failed with that error but for a newly created configuration. I had a configuration that was already running perfectly so I ended up copying the working configuration and editing it and it worked. I suspect was copying incorrectly formatted text because I pre-created the configurations locally on a text file.
after form submit for login/registration it shows 419|page expired. I used #csrf in the form. Its working on local server. but facing the issue in live server. Any help? I have 3 types of users and implemented multi auth for them. My code is given below:
config/auth.php
<?php
return [
'defaults' => [
'guard' => 'vendor',
'passwords' => 'vendors',
],
'guards' => [
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'manager' => [
'driver' => 'session',
'provider' => 'managers',
],
'vendor' => [
'driver' => 'session',
'provider' => 'vendors',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
'managers' => [
'driver' => 'eloquent',
'model' => App\Manager::class,
],
'vendors' => [
'driver' => 'eloquent',
'model' => App\Vendor::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
],
'managers' => [
'provider' => 'managers',
'table' => 'password_resets',
'expire' => 60,
],
'vendors' => [
'provider' => 'vendors',
'table' => 'password_resets',
'expire' => 60,
],
],
];
RedirectedIfAuthenticated.php
public function handle($request, Closure $next, $guard = null)
{
switch ($guard) {
case 'admin':
if(Auth::guard($guard)->check()){
return redirect()->route('admin.dashboard');
}
break;
case 'manager':
if(Auth::guard($guard)->check()){
return redirect()->route('manager.dashboard');
}
break;
case 'vendor':
if(Auth::guard($guard)->check()){
return redirect()->route('vendor.dashboard');
}
break;
default:
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
break;
}
return $next($request);
}
its perfectly working locally except on live server. pls help.
Please Try:
{{ csrf_field() }}
Instead of
#csrf
Some times #csrf Not work for me as well.
If there bug is not fixed, then you have to use One more thing,
php artisan key:generate
php artisan config:cache
php artisan cache:clear
php artisan view:clear
php artisan route:clear
It will clear All Cache and generate new token for your project.
Working Solution:-
case 1 : if you are running project in your local system like 127.0.01:8000 ,
then add SESSION_DOMAIN= in your .env file
or in your config/session.php 'domain' => env('SESSION_DOMAIN', ''),
and then run
php artisan cache:clear
case 2: if project is running on server and you have domain like "mydomain.com"
add SESSION_DOMAIN=mydomain.com in your .env file
or in your config/session.php 'domain' => env('SESSION_DOMAIN', 'mydomain.com'),
and then run
php artisan cache:clear
Thank You!
Another solution-
Add this piece of code into your .env function
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Set MEMCACHED_HOST=127.0.0.1 & SESSION_DRIVER=file
Hope it will save your time.
Thanks.
Same issue faced register post was not working.
Solution
In your .env change or add CACHE_DRIVER
CACHE_DRIVER=database to
CACHE_DRIVER=file
Don't forget to clear config and cache
u may have changed 'domain' => env('SESSION_DOMAIN', 'http://domaineName.com'),
in the file app/config/session
try to just put
'domain' => env('SESSION_DOMAIN', 'domaineName.com'),
or if u're working locally it's preferable to leave it empty
'domain' => env('SESSION_DOMAIN', ''),
May this be a solution
Can anyone help with the correct configuration within horizon.php to get a single supervisor to run multiple queues? I have tried:
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default', 'queue2'],
'balance' => 'simple',
'processes' => 10,
'tries' => 3,
],
as well as:
'supervisor-1' => [
'connection' => 'redis',
'queue' => 'default, queue2',
'balance' => 'simple',
'processes' => 10,
'tries' => 3,
],
The second queue shows up correctly in horizon and I can send jobs to them but they just do not get processed.
I am provisioned on forge and have my queues setup using redis with the following queue.php config:
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default', // Default Queue
'retry_after' => 90,
'block_for' => null,
],
in config/horizon.php
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default', 'queue2'],
'balance' => 'simple',
'processes' => 10,
'tries' => 3,
],
in supervisor : --queue=default,queue2
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/App/artisan queue:listen redis --queue=default,queue2 --sleep=3 --tries=3
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile= /var/www/html/App/storage/logs/worker.log