Laravel 5.4 - SoapClient not loaded from Job - php

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.

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');
}
}

Why Laravel 5.8 dispatch with database driver works like sync?

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.

Laravel ReflectionException in Controller

I'm trying to inject the class HotelsTransformer without success with the next code:
UserTransformer
<?php
namespace App\Transformers;
class UserTransformer extends Transformer
{
...
}
HotelsTransformer
<?php
namespace App\Transformers;
class HotelsTransformer extends Transformer
{
...
}
ApiHotelsController
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use \App\Hotel;
use \App\Transformers\HotelsTransformer;
class ApiHotelsController extends ApiController
{
protected $HotelsTransformer;
public function __construct(HotelsTransformer $HotelsTransformer)
{
$this->HotelsTransformer = $HotelsTransformer;
dd($this->HotelsTransformer);
}
When I inject UserTransformer, it's all OK, but when I change UserTransformer with HotelsTransformer it throws me this error.
I don't know why is this happening, because I cloned UserTransformer and change its name but same error persists.
Check your following namespace. May be it does not exist or namespace path is not correct
use \App\Transformers\HotelsTransformer;
Try to run composer dumpauto command.
Try running these commands from your terminal (from the root directory of your project)
// use sudo if it asks for the root permission
composer update
composer dump-autoload
php artisan config:clear
Rerun the app/project and try again.
These 2 commands will refresh composer loaded classes and clear the cache to make the project run freshly, hope it helps.!
Ok, I have solved it, the filename was wrong, changed:
app/Transformers/HotelsTranformer.php
to:
app/Transformers/HotelsTranformer.php
1 hour spent on that like a crazy, good job.

How to get the running path of a Symfony Console application?

Is there any way to get the running path in a Symfony Console application? For example (assuming php interpreter in PATH):
cd /tmp
php /home/user/myapplication/app/console.php mycommand
Should return /tmp as console.php was launched from /tmp.
getcwd() will do what you need. You can execute app/console from any directory, and PHP will know which one it is.
I used the following example to verify this.
<?php
namespace Acme\DemoBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class DemoCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('demo:cwd')
->setDescription('Get Current Working Directory')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(getcwd());
}
}

symfony 2 command issue

I am trying to run a php script form the command line.
sudo vim UpdateLatestIssuesCommand.php
But its giving me the following error:
PHP Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand' not found in /Applications/MAMP/htdocs/imagine-publishing/src/Imagine/CorporateBundle/Command/UpdateLatestIssuesCommand.php on line 12
I cant figure out why I am getting this error because the file its says it cant find is actually there.
Heres my code:
<?php
namespace Imagine\CorporateBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class UpdateLatestIssuesCommand extends ContainerAwareCommand
{
You have to run the command like this
php app/console demo:greet Fabien
where, demo:greet is the name of the command, Fabien is the argument
Reason
Because, console component has to bootstrap required resources for you before it runs the command.
FYI: Console Component

Categories