Why Laravel 5.8 dispatch with database driver works like sync? - php

I changed the queue driver in .env and config/queue.php from sync to database. Then I ran php artisan cache:clear.
I created a new job with the command php artisan make:job SendEmailJob
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Mail\SendEmailMailable;
use Illuminate\Support\Facades\Mail;
class SendEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* #return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
Mail::to('hello#example.com')->send(new SendEmailMailable());
}
}
Then I wrote this route in routes\web.php
use App\Jobs\SendEmailJob;
use Carbon\Carbon;
use Illuminate\Bus\Dispatcher;
Route::get('sendEmail', function(){
$job = (new SendEmailJob())->delay(Carbon::now()->addSeconds(5));
dispatch($job);
return 'Email is sent properly';
});
I stopped php artisan serve, the started again.
I chacked the result of env('QUEUE_DRIVER', 'database');, it returns database.
I ran php artisan queue:work, but there is no output.
The email sent to SMTP server like sync driver.
Is there anything I missed?
My PHP version is 5.6.

It was a PHP version problem. I Upgraded PHP to version 7.1 and problem solved.

Related

Event throw this error: Pusher error: cURL error 7: Failed to connect to 127.0.0.1 port 6001

UPDATE
What I have found out so far
I use Laravel sail for my Laravel 9 application. I have test run the laravel docker all down. and then started my app with php artisan serve. And i was able to fire my events. No more curl problem.
Locally I have PHP 8.1.12 running. The sail php container is running 8.1.13. So it must be a configuration issue. Either PHP or the webserver.
Original Question
I am currently working my way into the topic of websockets in Laravel. I have configured everything so far and created a testEvent. I was also able to trigger the event via tinker, so that the client received the message in the view.
Now I wanted to trigger the event from the PostController. And for this I created a function ws() where I wanted to fire my event.
// PostController.php
class PostController extends Controller
{
public function ws() {
event(new \ApplicationEvents\TestUpdate('{"user_id": "1", "message":42}'));
}
}
Problem: I get the following error message when I then route the controller with the ws method:
Pusher error: cURL error 7: Failed to connect to 127.0.0.1 port 6001 after 0 ms: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://127.0.0.1:6001/apps/12345/events?auth_key=abcde&auth_timestamp=1674832800&auth_version=1.0&body_md5=a5a5ea1c4270fbfeb5177d1c55b6b6ff&auth_signature=1f1127439fa366c8666765ab9bc337b8caebcafca617ca0fa0e8cfb1dd381ed7
Questions: 1. What am I doing wrong? and 2. What does this error message mean? 3. Why it working with tinker?
Notes: I use Laravel 9 and the websocket package https://github.com/beyondcode/laravel-websockets.
My Event*
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class TestUpdate implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $data;
public function __construct($data)
{
$this->data = $data;
}
public function broadcastOn()
{
return new Channel('userBus');
}
}

Symfony 4 run slowly on windows 10

I installed symfony 4 on windows machine. I created a controller and returned json data. I sended request in postman and response time is 1-5 second. It's very slowly this response time.
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class ScrapingController
* #package App\Controller
* #Route("/scraping")
*/
class ScrapingController extends AbstractController
{
/**
* #Route("/", name="scraping", methods={"GET"})
*/
public function index(){
return $this->json(['test'=>'ok']);
}
}
I run the project with this command.
php -S 127.0.0.1:8000 -t public/
would you help me with this topic?

Laravel 5.4 - SoapClient not loaded from Job

I have a problem getting PHP's SoapClient to work in my Laravel Job.
I created queueable job where I import the SoapClient with use SoapClient but Laravel is not able to find it.
But when I use the SoapClient in my Controllers it works flawlessly.
I checked phpini(): SoapClient is definitely enabled.
Any Ideas?
My Job Code:
<?php
namespace App\Jobs;
use SoapClient;
use Tymon\JWTAuth\Exceptions\JWTException;
use JWTAuth;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class ProcessQueuedRenderRequests implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
}
public function handle()
{
$soap = new SoapClient("http://mywsdl");
...
Errorlog:
[[2017-11-22 18:17:50] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'SoapClient' not found in /var/www/app/Jobs/ProcessQueuedRenderRequests.php:44
I use Docker with the Laradock configuration.
The joblistener ist started in this way:
docker-compose exec workspace bash
php artisan queue:listen
use
$soap = new \SoapClient("http://mywsdl");
I had the same issue once.
Found the problem. Soap was not installed in the workspace container.
When I start the joblistener like this it works:
docker-compose exec php-fpm bash
php artisan queue:listen
Still a bit strange since should also be installed in the workspace container according to my .env file.

My custom service provider doesn't work in laravel

I have created a custom service provider in my app called DemoServiceProvider in app/providers directory , and i register it in config/app as App\Providers\DemoServiceProvider::class
here is my DemoServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class DemoServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
dd("test");
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
//
}
}
the problem is i don't see "test" ,did i miss something ?
I have replicated your code and I retrieve:
php artisan serve --port=4433
"test"
Have you tried already:
composer dumpautoload
php artisan cache:clear
ok i found the solution ,it was with these two commands php artisan clear-compiled and php artisan cache:clear .

Lumen make:command

I'm trying to execute code within my Lumen install via the command line. In full Laravel , I've read that you can use commands to achieve this via "make:command", but Lumen does not seem to support this command.
Is there anyway to enable this command? Failing that, what's the best way of running code from the CLI in Lumen?
Thanks
You can use the artisan CLI in Lumen as the same way as in Laravel but with fewer built-in commands. To see all built-in commands, use the php artisan command in Lumen.
Although there is no make:command command at Lumen, you can create your custom command:
Add new command class inside the app/Console/Commands folder, you can use the sample class template of the framework serve command
Register your custom command by adding your created class to the $commands member inside the app/Console/Kernel.php file.
Except the command generating, you can use the Laravel docs for commands when working with Lumen.
Here is a template for a new command.
You can just copy and paste this in to a new file and start working.
I tested it on lumen 5.7.0
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class CommandName extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'commandSignature';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$this->info('hello world.');
}
}
Then register it on the Kernel.php file.
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
\App\Console\Commands\CommandName::class
];
When you create your command class use this:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
Instead of what was described above about using serve command example

Categories