Unable to Subscribe to Redis Channel Laravel 5.2 - php

I am following Laravel office Redis guide but i am having some problem
https://laravel.com/docs/5.2/redis#pubsub
After creating the command when i run " -> php artisan redis:subscribe" in console i get following error
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "redis" namespace.
I am unable to listen to Redis Chanel.
Redis Publish Channel method is working fine. To check this.
In console I typed "-> redis-cli" and then "subscribe mychannel"
On refreshing browser I am getting publish data in console.
I am unable to subscribe via Laravel.
I also tried using wild card
Route::get('/subscribe', function()
{
Redis::psubscribe(['*'], function($message, $channel) {
echo $message;
});
});
but browser keep loading and i don't get any data.
I also tried making a method in controller
public function subscribeChannel()
{
$redis = Redis::Connection();
$redis->subscribe(['channel'], function($message) {
echo $message;
});
}
This subscribeChannel method gives me following error
ErrorException in StreamConnection.php line 390:
strlen() expects parameter 1 to be string, array given
My configuration in config/database.php is folowing
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'read_write_timeout' => 0
],
],
Looking for help
thanks

Redis::connection & then subscribe not working for Laravel 5.2.
You can use following command for the same:
Redis::subscribe(['user_online_offline'], function ($message) {
echo $message;
});
If you want to use another connection for the same then you can use following command:
Redis::subscribe(['user_online_offline'], function ($message) {
echo $message;
}, $connection = 'socket');

Related

/usr/libexec/postfix/smtp does not send mail using Laravel on macOS

I have a Laravel 8 project that I want to send emails with. I develop it on macOS and I want to test it, but it does not work, but won't give any errors. (I replaced sensitive data with ********)
.env
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=********#gmail.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=********#gmail.com
MAIL_FROM_NAME="${APP_NAME}"
Note: I validated those settings, I also tested other working SMTP settings. So it's not a configuration issue in this file
mail.php
/// ...
'default' => env('MAIL_MAILER', 'mail'),
/// ...
'mailers' => [
'smtp' => [
'transport' => 'mail',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
/// ...
],
/// ...
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
resource_path('views/emails'),
],
],
/// ...
MailController.php
namespace App\Http\Controllers\API;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller as Controller;
use Illuminate\Support\Facades\Mail;
class MailController extends Controller
{
public function testMail(Request $request)
{
$email = '********#live.com';
$data = [
'title' => 'Test mail'
];
Mail::send(['html' => 'emails.testMail'], $data,
function ($message) use ($email, $data) {
$message->to($email)
->subject($data['title']);
});
$response = [
'error' => 0,
'to' => $email,
'data' => $data,
];
return response()->json($response, 200);
}
}
Note: There is a blade template containing only HTML for test purposes at resources/views/emails/testMail.blade.php. I also added the appropriate GET-route.
When I access the endpoint in Postman, I get
{
"error": 0,
"to": "********#live.com",
"data": {
"title": "Test mail"
}
}
Little Snitch popped up, asking if I want to allow /usr/libexec/postfix/smtp to access smtp.gmail.com, so I know the call goes through. I gave the process all rights to access any server and retried, but the mail will never reach my destination.
Yes, I checked the SPAM folder. Yes, I checked other credentials. Yes I tested manual delivery between both accounts. Yes, I tested with Little Snitch disabled, entirely. Yes, I checked the laravel.log and it reveals nothing.
I noticed, that I won't get any error from Laravel when I put in wrong information in the .env file (except when I change MAIL_MAILER).
How can I get the output from the SMTP process to find out what the issue is? How can I fix the issue?

LDAP Configuration Laravel5 - Authentication user provider [adldap] is not defined

I'm fresh beginner in Laravel 5.8 and i'm trying to develop an app with LDAP authentication.
I use this package : https://adldap2.github.io/Adldap2-Laravel/#/auth/setup
So, here is my configuration code (app.php) :
// service providers array
Adldap\Laravel\AdldapServiceProvider::class,
Adldap\Laravel\AdldapAuthServiceProvider::class
// aliases array
'Adldap' => Adldap\Laravel\Facades\Adldap::class
The LDAP configuration (ldap.php) :
'hosts' => explode(' ', env('LDAP_HOSTS', 'myserver1 myserver2'))
'port' => env('LDAP_PORT', 389),
'base_dn' => env('LDAP_BASE_DN', 'dc=mydc1,dc=mydc2,dc=mydc3'),
'username' => env('admin'),
'password' => env('admin'),
The authentication configuration (auth.php) :
// user provider fields
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'users' => [
'driver' => 'adldap',
'model' => App\User::class,
],
],
And then the UserController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Adldap\AdldapInterface;
class UserController extends Controller
{
protected $ldap;
public function __construct(AdldapInterface $ldap) {
$this->ldap = $ldap;
}
public function index() {
$users = $this->ldap->search()->users()->get();
return view('users.index',compact('users'));
}
}
And i got this error : Authentication user provider [adldap] is not defined.
Does anyone know this error and could tell me where my configuration can be wrong ?
Thansk for your help :)
EDIT : Idk if this could help but this morning the error precise me that the problem is in the welcome.blade.php file
You need to add some basic configuration in your .env file
ACCOUNT_PREFIX = local
ACCOUNT_SUFFIX = local
DOMAIN_CONTROLLERS = "172.16.20.142"
PORT = 389
TIMEOUT = 5
BASE_DN = "dc=local,dc=local"
USER_DN = "cn=users,dc=dummy,dc=local"
ADMIN_ACCOUNT_SUFFIX = #man.local
ADMIN_USERNAME = administrator
ADMIN_PASSWORD = dsds
LDAP_USER_CUSTOM_EMAIL_DOMAIN = #man.local
and check your aldap.config once
after that please clear cache of config by following command
php artisan config:clear && php artisan cache:clear && php artisan view:clear && php artisan route:clear && php artisan config:cache

Exception: Illuminate \ Broadcasting \ BroadcastException No message in PusherBroadcaster.php:119

Laravel 5.8
I am new to this whole pusher functionality and I've been following this tutorial and trying it out,
Create Web Notifications Using Laravel and Pusher Channels.
I've followed it step-by-step and when I get to the step to manually test the event by visiting the test url, I receive the following exception:
Illuminate \ Broadcasting \ BroadcastException
No message
C:\wamp\www\ares\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php
Here is the code:
$response = $this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $socket, true
);
if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
|| $response === true) {
return;
}
throw new BroadcastException( // <-- Exception at this line
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);
}
/**
* Get the Pusher SDK instance.
*
* #return \Pusher\Pusher
*/
public function getPusher()
{
return $this->pusher;
}
}
I've looked at a few other stack overflow articles which talk about changing encrypted: true to encrypted: false but that does not seem to affect anything.
I started working on Laravel 4 days ago and I came across this same problem when I was implementing a real-time chat application. After searching for many days, I discovered that this may vary depending on the version of Laravel you are running. If it is 5.8, you can fix this by adding the following code in the pusher.options array of the file config/broadcasting.php:
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
After adding this , your pusher array in the config/broadcasting.php should look like this.
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
],
],
You can then run php artisan config:cache(which may not be necessary in some cases) and finally run php artisan serve.You can consult your app in the pusher website and see the events you receive after sending your messages.
Hope it helps!!
If you're working on localhost try setting your .env file.
Set:
APP_URL=http://localhost
DB_HOST=localhost
And run
php artisan config:cache
Like i mentioned in a comment before this happens when the whole post goes wrong and wont deliver a response. Thats why the exception in line 116 is raised. I changed it to the domain before!
In my case i followed the code an found the method "createPusherDriver" in "vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php". At this place i inserted this
var_dump($config['key']);
var_dump($config['secret']);
var_dump( $config['app_id']);
var_dump($config['options']);
exit;
an noticed that my options still listed "host" => "localhost".
I removed those lines an cleared the config cache by executing php artisan config:cache
On next reload my event was fired an logged in the console.
Worked perfectly up to my Laravel 5.8 version. But encrypted' => true or encrypted' => false did not matter in this case for such Laravel version. But, following PUSHER suggestions, I put to broadcasting: 'useTLS' => true,.
This is the final result to me:
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'useTLS' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
]
Thanks to dear #Bitart
'useTLS' => true
option solved my issue.
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
]

Laravel: Jasper reports in laravel lumen5.6

I already implemented jasper reports with laravel and it works fine for me. Now i shifted to laravel lumen for api building so i try to integrate jasper as same as i integrate in my laravel projects but in laravel lumen it throws some error as below:-
Call to undefined method Laravel\Lumen\Application::booting()
below is my connection code
class_alias(JasperPHP\JasperPHPServiceProvider::class,'JasperPHP');
$app->withFacades(); $app->withEloquent();
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
$app->register(JasperPHP\JasperPHPServiceProvider::class);
Please share your thoughts, Thanks in advance
I finally come up with a solution and it works fine with laravel lumen 5.6 below are the steps:-
1)Install JasperReports 6 library by below command
composer require cossou/jasperphp
In bootstrap/app.php uncomment this line $app->withFacades(); and add below code
$app->singleton('jasperphp', function ($app) {
return new JasperPHP;
});
$app->alias('JasperPHP\JasperPHPServiceProvider\JasperPHP', 'JasperPHP');
Controller part Changes
namespace App\Http\Controllers;
use JasperPHP\JasperPHP as JasperPHP;
use Illuminate\Http\Request;
//dd(__DIR__ . '/../../vendor/cossou/jasperphp/examples/hello_world.jasper');
class ReportController extends Controller {
public function generateReport() {
//JasperPHP::compile(base_path('/vendor/cossou/jasperphp/examples/hello_world.jrxml'))->execute();
$jasper = new JasperPHP;
$filename = 'gau';
$output = base_path('//public/reports/' . $filename);
$jasper->process(
base_path('/vendor/cossou/jasperphp/examples/LaravelIreporTest.jasper'),
$output,
array("pdf"),
array("test" => "Tax Invoice"),
array(
'driver' => 'mysql',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'database' => 'database name',
'port' => '3306',
)
)->execute();
}
}

Laravel Password remind - connection refused 61

I am stumped.
I am using Laravel's Password::remind, which has already been written for me, so there is nothing that I have changed:
try {
$reset = Password::remind($credentials);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
When I submit the form, then I receive the following exception:
Exception
Connection could not be established with host localhost [Connection refused #61]
Which points to my throw exception line above
In my app/config/mail.php file, I have tried everything from mail to sendmail, from localhost to smtp.gmail.com - whatever I change in this config file, Laravel still thinks that it is localhost. Even tried "/usr/sbin/sendmail -t -i"
I have restarted apache and fpm - the error does not change.
When I try mail(email, title, message) - it works just fine. Of course, my goal is to not just send an email but to use Laravel's Password::remind - function where it sends an email with a link for the user to reset their password.
I have changed the /usr/local/etc/php/5.5/php.ini file, both the smtp and smtp_port
What do I need to do, this seems so straight forward in their documentation and no one else has complained about this issue for connection refused # 61. There are other connection refused and they have nothing to do with the built in Password::remind. This is driving me nuts.
I am running fpm-nginx.
Thanks in advance
Just to be on the safe side in respect to any configuration issues, I suggest you to try your application in a closed environment such as Homestead. This way, i.e. by relying on a fresh virtual machine, you might be able to figure out whether it is a configuration issue on the level of the different applications (apache, php, etc.) you are using. Otherwise, you would have to reinspect your code again. You can find more information on Homestead here: http://laravel.com/docs/4.2/homestead
OK, there were a couple of configurations that had to be in place and I am posting this answer in case anyone else using Yosemite is having this issue.
First, from my searching for the error "Connection refused #61" this is usually related to connectivity with a database as Korush suggested above. However, if I typed in an email that was not part of the database, Laravel would come back with a message that such and such email was not found, which told me that it was connected to the database, from the stand point of searching the email that was entered.
However, if a person does not have a "password_reminders" table in their localhost database, then a person would receive a connection refused error - be sure that you have this for Laravel to use in your localhost db:
CREATE TABLE password_reminders (
email VARCHAR(50) NOT NULL,
token VARCHAR(100) NOT NULL,
created_at TIMESTAMP
)
Second, Laravel can use the mail server on your system. In my case, I am using Yosemite, which has "postfix" available in the terminal:
sudo postfix start
Here is my local config which allows Laravel to use the "password_reminders" table, which is located in app/config/database.php:
'local' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'yourdb',
'username' => 'yourusername',
'password' => 'yourpassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Within the app/config/mail.php:
'driver' => 'smtp',
'host' => 'localhost',
'port' => 25,
'from' => array('address' => 'service#yourdomain.com', 'name' => 'Your Company'),
'encryption' => '',
'username' => null,
'password' => null,
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
I still need to figure out how to get the redirects and messages to display, but this is working for the emailing a link to reset the password:
public function request()
{
$message = "";
$session = null;
$request = array('email' => Input::get('USER_EMAIL'));
Password::remind(Input::only('USER_EMAIL'), function($message)
{
$message->subject('Password Reminder');
});
if ($request == 'reminders.sent') {
$session = 'message';
$success = true;
$message = 'Email with further instruction has been sent to "' . Input::get('USER_EMAIL'). '".';
return Password::remind($request);
} elseif ($request == 'reminders.user') {
$session = 'error';
$success = false;
$message = 'Email Address: ' . Input::get('USER_EMAIL') . ' WAS NOT FOUND!';
return Password::remind($request);
}else{
$message = 'Not meeting either condition "' . Input::get('USER_EMAIL') . '".';
return Password::remind($request);
}
Session::flash($session, $message);
return Redirect::to('/').with($session, $message);
}
Here are my routes related to password remind:
Route::get('password/reset', array(
'uses' => 'PasswordController#remind',
'as' => 'password.remind'
));
Route::post('password/reset', array(
'uses' => 'PasswordController#request',
'as' => 'password.request'
));
Route::get('password/reset/{token}', array(
'uses' => 'PasswordController#reset',
'as' => 'password.reset'
));
Route::post('password/reset/{token}', array(
'uses' => 'PasswordController#update',
'as' => 'password.update'
));
Maybe it is trying to send an e-mail and it is not working.

Categories