I am trying to configure my Laravel app so all my Laravel Queue Failed Jobs goes to Redis instead of mysql.
Currenly my jobs are configured to use redis but failed_jobs still goes to MySql Database
Didn't find anything on StackOverflow/Laravel
Laravel 5.4
Redis
PHP 7.0
Please help!
Check your settings in config/queue.php, you should find following values:
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
'table' => env('QUEUE_FAILED_TABLE', 'failed_jobs'),
]
Change the connection and table on whatever you need.
Related
I'm working on a Laravel project and I want to use Redis to store session data for improved performance. I have set up Redis correctly and it's working fine with basic functionality. However, I'm having trouble getting the auth::attempt function to work with Redis.
Here's my current auth::attempt code:
if (Auth::attempt(['email' => $email, 'password' => $password])) {
// User authentication successful
} else {
// User authentication failed
}
This works fine with the default session driver in Laravel, but I want to use Redis for better performance. I have tried changing the SESSION_DRIVER variable in my .env file to 'redis' and set the Redis connection in config/database.php, but I'm still getting an authentication error.
I'm not sure what I'm missing. Can anyone help me understand how to use Redis with auth::attempt in Laravel? Thanks in advance!
When using Redis for session storage in Laravel, you need to ensure that your Redis server is running and that your Laravel application is configured to use Redis as the session driver.
To set Redis as your session driver, you can change the value of the SESSION_DRIVER variable in your .env file to redis. You can also configure the Redis connection in the config/database.php file. Here's an example configuration:
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'table' => 'sessions',
'expire_on_close' => false,
],
Once you've configured Redis as your session driver, you can use the Auth::attempt method as usual. However, if you're still encountering authentication errors, there are a few things you can try:
Make sure your Redis server is running and accessible from your
Laravel application.
Check your Redis configuration in the config/database.php file to
ensure that it's set up correctly.
Clear your Laravel application's cache using the php artisan
cache:clear command.
Check your Redis server's logs for any errors or issues that might
be causing the authentication failures.
I'm making a second connection of my project in laravel with a view in an MsSql database, I configured my .env and config correctly, however this is an error of memory overflow:
$ php artisan tinker
Psy Shell v0.10.5 (PHP 7.3.24-3+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> use App\Condinvest\BoletoPropCondominio as BPC
>>> BPC::first();
Illuminate\Database\QueryException with message 'SQLSTATE[HY001] Unable to allocate sufficient memory (meudominio.com.br:5000) (severity 8) (SQL: select top 1 * from [View_Boleto_Prop_Condominio])'
>>>
already changed in my php.ini:
memory_limit = 128M
but the error continues.
My models briefly look like this:
BaseView.php
<?php
namespace App\Condinvest;
use Illuminate\Database\Eloquent\Model;
class BaseView extends Model
{
protected $connection = 'condinvest';
}
BoletoPropCondominio.php
<?php
namespace App\Condinvest;
class BoletoPropCondominio extends BaseView
{
protected $table = 'View_Boleto_Prop_Condominio';
protected $fillable = [
'Id_Condo_lan',
...
'Id_titular'
];
}
when I do the same query directly through the command terminal:
SELECT TOP 1 * FROM View_Boleto_Prop_Condominio;
returns my data successfully.
Can anyone tell me what may be happening, or how I can debug better to understand where the error is, please.
EDIT
>>> DB::connection('condinvest')->getConfig()['driver']
=> "sqlsrv"
Since the error is apparently being reported by the database process (not the php process), I would not expect changes to memory limits in php.ini to have any effect.
I found this issue which mentions this specific error when using a deprecated driver with MSSQL Server.
To check which driver Laravel is using, type DB::connection()->getConfig()['driver'] into your Tinker console. If you see sqlsrv then everything is ok here, but if you see dblib then this might be the source of the error. This problem was supposedly fixed in Laravel 5.7 to prefer the supported drivers if more than one is available, but it's also possible that your database.php config file uses the wrong one.
It is also possible that the memory limits of the database server or the system it resides on are actually being exceeded. Being able to run the query in a command prompt without getting the error suggests that this is not the case, but it may still be worth investigating. If the available memory is very low then it's possible that there is not enough to run both php and the database query at the same time. You can check the available system memory by running the free -h command in the terminal, as long as the database process is running on the same machine as your terminal. However, if you are using a shared hosting provider then it is possible that the database is on a separate machine.
If it helps, i encoutered the same issue. What i did in order to fix it was to check my configuration in database.php, if you use sqlserver, make sure you have charset set to utf8 as follows. It was previously set to utf8mb4.
'sqlserver' => [
'driver' => 'sqlsrv',
'host' => env('DB_SQL_HOST'),
'port' => env('DB_SQL_PORT'),
'database' => env('DB_SQL_DATABASE', 'forge'),
'username' => env('DB_SQL_USERNAME', 'forge'),
'password' => env('DB_SQL_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'options' => [
PDO::ATTR_TIMEOUT => 300
]
]
I am trying to implement Redis publishing in my local RESTful API which is built in Laravel for the purposes of implementing a chat system later on with Web Sockets. I intend to read them from a Node.JS server later on.
I am using Redis::publish to publish a simple message to my test-channel.
However, for some reason Laravel doesn't seem to publish to it.
I have also noticed that when I call Redis::set, whatever I set doesn't get persisted in Redis, but using Redis::get I can read the values that I'm setting.
public function redis(Request $request) {
$data = $request->validate([
'message' => 'string|required'
]);
Redis::publish('test-channel', 'a test message');
return 'Done';
}
I am using the code above in the api/redis route:
Route::post('/redis', 'API\MessageController#redis');
I have subscribed to the test-channel using the redis-cli command.
If I manually publish a message to the test-channel using the redis-cli in a terminal instance, I properly receive the messages that I am publishing. However, they don't seem to get published with Laravel for some reason.
What I can notice while running php artisan serve and visiting the aforementioned route is Laravel logging the following:
[*timestamp*] 127.0.0.1:39448 Accepted
[*timestamp*] 127.0.0.1:39448 Closing
The port after 127.0.0.1 appears to be random.
I tried both php-redis php extension and the predis package, just to be sure that it isn't any one of them, but I get the same result with both of them. I am currently using php-redis with both igbinary and redis extensions enabled in /etc/php/config.d and have removed the Redis alias from config/app.php.
I am using PHP 7.4, Laravel 6.0 and Redis 5.0.7 on Manjaro.
Been there, discovered that with:
$ redis-client
psubscribe *
will show you what's going on.
Chances are that your default config/database.php contains something like:
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
],
In that case, the channel name will be prefixed with this prefix option.
So you can just comment this option, or, if you keep it, be sure to subscribe to the right channel
Redis::publish('test-channel', 'a test message');
$prefix = config('database.redis.options.prefix');
$channel = $prefix . 'test-channel';
return "Done. (published on $channel)";
I need to configure Laravel 5 to use ODBC accessing Visual FoxPro tables through Eloquent ORM.
I have tried inserting the following entry in the 'connections' list of 'database.php' file, but the application returns the error "Unsupported driver [odbc]":
'odbc' => [
'driver' => 'odbc',
'dsn' => 'Visual FoxPro Database',
'database' => '',
],
Is there a way to use ODBC to access VFP tables, like I did using PHP flat application? Every help will be appreciated.
Currently Laravel 5 indicates that it supports the following database systems: MySQL, Postgres, SQLite, and SQL Server.
https://laravel.com/docs/5.0/database
You could try installing the next library,
https://github.com/luads/php-xbase
i am working on Redis to store data Everything is working fine in my local system. i have successfully installed redis also in laravel with this command composer require predis/predis also and Redis setup of window also installed. Now when i store data in Redis like this:-
Redis::set('first',"My first Test"); // put data in Redis key
echo Redis ::get('first'); // get data
Above code is working fine in my local system. when i try to use this code in live server it is showing the below error:-
Please help me to resolve this issue. We are using amazon-ec2 server Thanks in advance :)
I had the same issue. But I believe its related to php 7 rather than Larevel 5.4 because I'm using Laravel 5.1 and I still have the problem.
I came across 2 solutions
Use use Illuminate\Support\Facades\Redis; instead of use Redis; if you want to call the Redis methods statically.
Change to dynamic calling
$redis = new Redis();
$redis->set('boo','Have beer and relax!')
$redis->get('boo');
Just remove or comment out extension=php_redis.dll from your php.ini
Laravel and server Redis conflicts with name "Redis"
This will work
In Laravel database config you can define a client for your Redis handler.
As you have installed predis, your Redis database configuration should look like this
'redis' => [
'client' => 'predis',
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
PhpRedis extension and Laravel alias for Redis Facades are same which is creating the issue. In case you want to use the PhpRedis extension you need to change the alias keyword defined in app.php and client in the database config.