Get websocket data in laravel controller - laravel

I have an external WebSocket link where im getting data. My requirement is to receive those data in laravel controller and handle them.
How to listen in controller.

Finally i found the solution.
this has helped me.
$clientWebSoket = new \WebSocket\Client(
'wss://somelink'
);
$clientWebSoket->send(
'{"method":"test","symbols":"some data"}'
);
while ($i) {
try {
$message = $clientWebSoket->receive();
dump($message);
} catch (\WebSocket\ConnectionException $e) {
dd($e);
}
}
$clientWebSoket->close();

Related

How To Check If Notification Is Sent Successfully In Laravel

I am unable to find in the documentation of how to handle the notification (what to do if notification is sent successfully or not)
NotificationController
public function AskForLevelUp()
{
$admin = User::where('is_admin', 1)->first();
$sendNotification = Notification::send($admin, new LevelUpNotification(Auth::user()->id));
if ($sendNotification->success()) // **HOW TO DO THIS CORRECTLY**
{
return back()->with('success', 'Your request has been submitted, please wait for admin confirmation.');
}
else
{
return back()->with('failure', 'Something went wrong, your request is not submitted. Please try again later.');
}
}
I've also read that send() has void return value here. Does anyone know how to handle this?

how to solve 419 PAGE EXPIRED, using laravel8 mongodb

Im using laravel 8 with jetstream authentication and bongodb before changing database from mysql to mongodb (using jenssegers/laravel-mongodb) it was everything work fine but when i use mongodb every post methode doesn't work it give me this erreur ('419 PAGE EXPIRED')
i know where is the probleme exactlty is in this function
namespace Illuminate\Foundation\Http\Middleware;
protected function inExceptArray($request)
{
foreach ($this->except as $except) {
if ($except !== '/') {
$except = trim($except, '/');
}
if ($request->fullUrlIs($except) || $request->is($except)) {
return true;
}
}
return false;
}
i dont know what i miss why it always return false
I changed to SESSION_DRIVER=fil and it worked for me

Guzzle and react Promise cause infine loop

I use Guzzle 6 to call asynchrous request and I then use React Promise/Deferred and Event loop , then I use php-react-block to get result by resolved.
Firstly I send http Request as following:
public function callService($endpoint){
$requestDeferred = new React\Promise\Deferred();
$requestParams = new Request("POST", $endpoint, $header, $message);
$client = new Client();//Guzzle http client
$client->sendAsync($requestParams)->then(
function (ResponseInterface $res) use($requestDeferred) {
// $res->getStatusCode() . "\n";
$requestDeferred->resolve($res->getBody()->getContents());
},
function (RequestException $e) use($requestDeferred) {
$requestDeferred->reject();
}
);
return $requestDeferred->promise();
}
After I call this method as following
$loop = React\EventLoop\Factory::create();
$requestPromise = $this->callService( $endpoint);
$responseXml = Clue\React\Block\await($requestPromise, $loop);// I want to block/wait to until promise is resolved and get resolved value.
But when I call Clue\React\Block\await($requestPromise, $loop) , the system loops infinetly and any promise can not be resolved. Also I added queue->run() method to run method of related event (LibEvent). But system still loops infinetly.
Why the system loops infinetly?
Thanks for your helps

Magento issue with email charset

I have a little issue. I'm using to send mail in my custom module this piece of code:
$content = 'Wiadomość testowa ąśźć';
$mail = Mage::getModel('core/email');
$mail->setToName($name);
$mail->setToEmail($email);
$mail->setBody($content);
$mail->setSubject($subject);
$mail->setFromEmail('test#test.com');
$mail->setFromName("Test");
$mail->setType('html');
try {
$mail->send();
Mage::getSingleton('customer/session')->setData('success',Mage::helper('adminhtml')->__('Your request has been sent'));
}
catch (Exception $e) {
Mage::getSingleton('customer/session')->setData('error',Mage::helper('adminhtml')->__('Unable to send email.'));
}
How can I set utf-8 charset before sending email in magento mail function. ?
I get email with no utf-8 charset in email body.
SOLVED
I created sendZendMail function in helper.
I used this function, instead Magento core/email:
public function sendZendMail($name,$email,$subject,$content){
$mail = new Zend_Mail('UTF-8');
$mail->setBodyHtml($content);
$mail->setFrom('your#frommail.com');
$mail->addTo($email, 'No reply');
$mail->setSubject($subject);
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Mail was sucessfully send.');
}
catch(Exception $ex) {
Mage::getSingleton('core/session')->addError('Unable to send email.');
}
}
kristoff, I had the same issue before with Portuguese, which also has special characters. I've sorted it out by using the function htmlentities() for accented words. The Zend Mail Object is a bit retarded. I hope it helps.

CodeIgniter - UserAgent

I have the below code to check if the user is coming from a mobile, if they are I want to load a different page but it doesn't seem to be working...
Can anyone shed any light on the below:
if($xmlRefresh==1) {
$viewData['content'] = $this->load->view('newquote/policy_xml', $viewData);
$this->load->view('layout', $viewData);
} elseif ($this->agent->is_mobile()) {
$this->_showPage("newquote/policy_mobile", 'Customise', $viewData);
} else {
$this->_showPage("newquote/policy", 'Customise', $viewData);
}
I keep getting an internal server error, can anyone spot the problem...
Look at your system/core/Loader.php, function view() that will be $this->load->view returns void unless you add third parameter. try with:
$viewData2['content'] = $this->load->view('newquote/policy_xml', $viewData1, TRUE);
and
'''
$this->_showPage("newquote/policy_mobile", 'Customise', $viewData2);
Note: $viewData2 is different with $viewData1
are you calling this in controller?
What is the 500 (internal server) error??
Did you load the library user_agent??
$this->load->library('user_agent');
if($xmlRefresh==1) {
$viewData['content'] = $this->load->view('newquote/policy_xml', $viewData);
$this->load->view('layout', $viewData);
} elseif ($this->agent->is_mobile()) {
$this->_showPage("newquote/policy_mobile", 'Customise', $viewData);
} else {
$this->_showPage("newquote/policy", 'Customise', $viewData);
}
Finally if you want serve the mobile pages, use post post or pre hooks to determine the user agent before view is executed (if you want to play around)
i have one idea, may be help u
you can replace redirect()/$this->load->view() to $this->_showPage("newquote/policy_mobile", 'Customise', $viewData);

Resources