Laravel Ratchet not reading config file after vendor:publish - php

Im trying to make Socket server base on laravel-ratchet.
ive done installation steps from git :
1."composer require askedio/laravel-ratchet"
2. "$ php artisan vendor:publish --provider="Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider"
then ive entered class address in app.php like this :
Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider::class,
now from this help ive created my simple socket IoServer class in app folder (App/MyRatchetSocketServer):
<?php
namespace App;
use Ratchet\ConnectionInterface;
use Askedio\LaravelRatchet\RatchetServer;
class MyRatchetSocketServer extends RatchetServer
{
public function onMessage(ConnectionInterface $conn, $input)
{
parent::onMessage($conn, $input);
if (!$this->throttled) {
$this->send($conn, 'Hello you.');
$this->sendAll('Hello everyone.');
$this->send($conn, 'Wait, I don\'t know you! Bye bye!');
$this->abort($conn);
}
}
}
then ive changed my /config/ratchet.php to this :
<?php
return [
'class' => \App\MyRatchetSocketServer::class,
'host' => '127.0.0.1',
'port' => '8989',
'connectionLimit' => false,
'throttle' => [
'onOpen' => '5:1',
'onMessage' => '20:1',
],
'abortOnMessageThrottle' => false,
'blackList' => [],
'zmq' => [
'host' => '127.0.0.1',
'port' => 5555,
'method' => \ZMQ::SOCKET_PULL,
],
];
and in final part im going to start my service with serve :
php artisan ratchet:serve
and it gives this error :
Starting WampServer server on: 0.0.0.0:8080
In RatchetServerCommand.php line 204:
Askedio\LaravelRatchet\Examples\Pusher must be an instance of Askedio\LaravelRatchet\RatchetWampServer to create a Wamp server
my guess is that , serve command is bypassing the ratchet config file.
also if i try this :
php artisan ratchet:serve --driver=IoServer --class="App\MyRachetSocketServer::class"
the error changed to this :
Starting IoServer server on: 0.0.0.0:8080
In RatchetServerCommand.php line 155:
Class 'App\MyRachetSocketServer::class' not found
the file path is correct (bottom pic). dont know what to test next ?!
Im using Xamp , Vscode , Laravel 5.5.

I had the same problem long time ago
after a few try , find out that it was a cache problem.
try this Package for clearing cache with this command :
php artisan clear:data
or u can use these generic command in order:
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan clear-compiled
php artisan config:cache
and finaly , try your server command as follows :
php artisan ratchet:serve --driver=IoServer
hope that helps :)

Related

Laravel database still use old name after .env changed

Edit:
php artisan config:cache work nice, but now I got other problem.
the URL giving me Error 500
I upload a project to a new subdomain area after I changed .env file
when I open URL I still got an error with the old database and user
I tried to check online with the .env file but - I don't know where he stored this database, I tried to see where is this name with ctrl+f but - nothing found
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=faceterc_hot
DB_USERNAME=faceterc_hot
DB_PASSWORD=testpro
I expect to get the same error maybe but not with the old database name.
and this gives me a indicate that maybe the file or something not changed or he using the other details from I don't know where
Good, practice for, If you change in a .env file first restart the server using below command.
php artisan serve
then after run below more command for clear old cache and config.
composer dump-autoload
php artisan config:cache
php artisan config:clear
You can simply do a
php artisan config:cache
In case you are on a shared hosting, you can change the values in config/database.php to only use the set values in your .env. Setting it like this will make sure, it only use the .env values.
mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
php artisan config:clear Solve the problem with DATABASE error
just ran :
php artisan config:clear
with ssh at the main folder.
Just execute
php artisan config:cache
as the laravel cache's the environment files rather than accessing the data from it on every request.
It's always a good practice to run these couple of commands when you change any environment related variable:
php artisan config:clear
php artisan cache:clear
Execute these commands:
php artisan config:cache
php artisan route:cache
php artisan optimize
That will clear your env cache and it should do.

The controllers namespace must start with your application namespace: App</error >

I found this error when wanting to publish my namespace in the file voyager.php with the instruction, `php artisan voyager:controllers
route:
voyager.php
'controllers' => [
'namespace' => 'TCG\\Voyager\\Http\\Controllers',
'namespace' => 'App\\Http\\Controllers\\Voyager',
],
error message:
**The controllers namespace must start with your application namespace: App</error>**
I have applied these commands
composer dumpautoload
php artisan config:cache
php artisan cache:clear
composer update
install and uninstall voyager
I use the version of laravel 5.5
Also insert the provider
TCG\Voyager\VoyagerServiceProvider::class,
Change
'namespace' => 'TCG\\Voyager\\Http\\Controllers',
To
'namespace' => 'App\\Http\\Controllers\\Voyager',
For detail visit GitHub Issue, GitHub Issue 2
Please try to following
php artisan optimize
php artisan voyager:controllers
You will be success.
You can use your own Controller by extending Voyager's Controllers. To do it, first define your controller Namespace at
config/voyager.php :
'controllers' => [
'namespace' => 'App\\Http\\Controllers\\Voyager',
],
then run php artisan voyager:controllers, voyager will now use the child controllers which will be created at
App/Http/Controllers/Voyager
Just clear the cache after change the namespace
php artisan config:cache

Laravel 5.5 Queue: No connector for []

I have two websites running identical laravel 5.5 project. In fact both websites hosted on the same server. One of them works, another one has troubles with queues. I have double-checked everything.
.env:
...
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=database
QUEUE_DRIVER=database
...
conf/queue.php
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
I do have empty jobs table as well.
Whenever I do try to run queues I'm getting an error
php artisan queue:work --daemon
In QueueManager.php line 172:
No connector for []
Please check the config queue drive setting. If use Redis, you can use php artisan tinker check
current the config.
Check command queue:
php artisan queue:work redis --queue=QUEUE_NAME --tries=3 --memory=128 --timeout=300
Check job listen by command line:
ps aux | grep php
I just had to specify a "connection" (database for my case) after queue:work command like below:
php artisan queue:work database --queue=Q_NAME
and the error disappeared!
Hi I encountered the same problem and couldn't find the solution but I followed laravel deploy optimizations, like cache config, view and routes which result into this. (I am not sure why).
I followed these and it worked like magic. (I don't know why it worked)
php artisan config:clear
php artisan route:clear
php artisan view:clear

Laravel Scout production error with TNTSearch driver

Searching using the TNTSearch driver works in a Homestead environment however on production it returns error: the below error,
Symfony\Component\Debug\Exception\FatalThrowableError: Class
'AlgoliaSearch\Version' not found on
vendor/laravel/scout/src/EngineManager.php:31
However my .env has SCOUT_DRIVER=tntsearch and the config file scout.php has:
'driver' => env('SCOUT_DRIVER', 'tntsearch'),
'tntsearch' => [
'storage' => storage_path(),
'fuzziness' => env('TNTSEARCH_FUZZINESS', false),
'fuzzy' => [
'prefix_length' => 2,
'max_expansions' => 50,
'distance' => 2
],
'asYouType' => false,
'searchBoolean' => env('TNTSEARCH_BOOLEAN', false),
]
The problem is that I am not using Algolia search and my composer file has Scout and TNTSearch driver. The search works in my local Homestead environment just not on the production server.
Confirm that SCOUT_DRIVER=tntsearch has been added to your .env file.
For me personally, I had added SCOUT_DRIVER=tntsearch to my local .env file, but not my .env file for the environment with the issue. Don't forget to run php artisan config:clear after adding the env var.
Thanks to #m33bo for pointing me in the right direction!
I worked it out, I had uploaded my project but for some reason the .index file that is needed sync'd but did not work. If this happens to you on live make sure you Git or SVN or whatever the index or run php artisan scout:import App\\Your\\Model

spatie/laravel-backup "mysqldump" doesn't recognized when I run it through Artisan class

I'm using spatie/laravel-backup in a WAMP localhost.
It works fine when I type manually in the windows cmd:
php artisan backup:run
But when I try to run the backup using the laravel Artisan class:
Artisan::call('backup:run');
It throw an error:
'mysqldump' not recognized ...
In the laravel mysql config I've also specified the path to the dumper:
'mysql' => [
'driver' => 'mysql',
// ...
'dump' => [
'dump_binary_path' => 'E:/wamp/wamp64/bin/mysql/mysql5.7.9/bin',
],
],
How can i fix that?
EDIT
Probably it's just support "bug" for windows (finded out thanks Loek's answer), as the author says, so can I run a backup in a controller without a command safely? maybe with something like:
use Spatie\Backup\Tasks\Backup\BackupJobFactory;
BackupJobFactory::createFromArray(config('laravel-backup'))->run();
As the command itself.
I believe it's the forward slashes. Try this:
'mysql' => [
'driver' => 'mysql',
// ...
'dump' => [
'dump_binary_path' => 'E:\\wamp\\wamp64\\bin\\mysql\\mysql5.7.9\\bin',
],
],
EDIT
Support for Windows is wonky at best, with multiple "This package doesn't support Windows" comments from the creators on GitHub issues. This one is the latest: https://github.com/spatie/laravel-backup/issues/311
It could also be a permission problem. Executing from the command line is probably happening from another user than executing from the web server, so Windows is denying access to mysqldump.
2nd edit
As long as you make sure the controller only gets called when it needs to be, I don't see why this wouldn't work!

Categories