how to add real time chat with notifications in laravel project - php

I want to add real-time chat with notifications to my Laravel project.
How can I do that and also save the chats in MySQL? Is there any chat framework that I can use??

Because the best way to implement a chat uses websockets, which are not supported by default in PHP you need a service like pusher or running a Laravel Echo server which is based on socket.io (a Node JS lib).
Pusher is something like "websockets as a service" and has a tutorial: https://blog.pusher.com/how-to-build-a-laravel-chat-app-with-pusher/
And then there is this demo:
https://github.com/jplhomer/laravel-realtime-chat-demo
If you cannot run or pay for any of the previously mentioned websocket implementations, you could consider using long polling in javascript, but that is a worse solution. It takes more resources and works far less better.
Web Chat Application using Long-Polling Technology with PHP,MySQL and jQuery

Related

WebSockets with Laravel

I am new to the Websocket world. I have implemented 2 API's one for getting the comments and one for posting the comments to a post. Using the following technologies.
Laravel 5.7
http://socketo.me/
Vue + Echo
Following https://www.youtube.com/playlist?list=PLwAKR305CRO9rlj-U9oOi4m2sQaWN6XA8
The above WebSockets are working fine with browser to browser in Axios calls, my question is how can I write WebSockets for Android/iOS developers and test like we do for API's and use postman for testing.
I have looked into iOS developer code they were using something like ws://123.123.123.123/socket Please guide how can I convert my WebSockets as ws: and deploy to stage server?
How to make a WebSocket on the above-mentioned technologies that iOS/Android developers can use directly?
I am sure my question looks basic, guidance can change it :-)
I want to send coordinates(lat,lng) from one device to another device as the location of the rider. If I am not wrong one device will push and another device will listen?
How can I write those WebSockets calls?

Socket.io like PHP Implementation

I am working on a little personal project on Ionic2 framework, and one part of my application requires a chat to be implemented. So I went and read about Socket.IO and it's implementations and it is really awesome. But the drawback for my project is that the frontend will not be able to host NodeJS, so I had to quit the idea of using Socket.io.
is there any alternative/Solution to make the PHPserver maintain a bidirectional connection for the chat? My guessing was to use GET/POST between the Ionic App and the server but that will be heavy on both client and server since it has to check on every short amount of time (less than a second to give the real-time like behavior).
Thank you.

Update/Notify HTML from backend asynchronously without AJAX polling

I am developing a dashboard for CRM, where admins can view/process all orders.
Requirement:
Whenever a user places an order from website/mobile app, one dedicated PHP file is called from which the user data is inserted into the Database.Now I want to notify the online admin about the new order without refreshing the page.
I know it's very easy if you use AJAX polling, but I don't want to use AJAX polling. And I tried PHP Websocket also by referring this tutorial, but unfortunately that doesn't work on live server.
Kindly let me know if there is any workarounds or any technology I can implement to achieve my requirement.
I am using HTML5 frontend and PHP for backend.
You should select a WebSocket framework like socket.io. There are many advantages of not using web sockets directly due to web socket limitations in some browsers and platforms . Socket.io frameworks like socket.io addresses this issue by being backward compatible.
Socket.io original back-end implementation runs on node.js. So unless you don't want to have node js, look for a socket.io php wrapper like elephant.io.

Does drupal or joomla allow a combination node.js and socket.io with php?

I'm looking into the development of a site where socket use is a must for real time updates. I understand with wordpress it is difficult to incorporate node.js and socket.io and was wondering if this is the case with drupal. Specifically could I incorporate node.js and socket.io with php? What specific steps would I need to take? I appreciate the help and of course if you give me a good answer, I'll rate you up.
There are currently Node.js modules that connect to Drupal, Joomla, and WordPress. I wrote the one for Joomla: https://github.com/jlleblanc/nodejs-joomla You can find all of these through NPM. First, you would download one of these modules, then you would also download the Socket.io module. Then you would write server side code connecting the CMS to Socket.io. Finally, you would write client-side code to talk to the socket running in Node.
You can have it separated and since you want some client-server communication with node.js, you can have it - outside Drupal (this is the easiest and cleanest way).
CMS you use (be it Drupal or Wordpress) does not limit your JavaScript from using socket.io and node.js for the calls you want to be made outside the CMS server-side code. You can eg. read the same database Drupal/Wordpress does, but using Node.js and returning the results directly to the client-side JavaScript script.
You can integrate Socket.IO with whatever technology you like, but you need to think of them as 2 separate parts that need to communicate.
I see 2 solutions for Socket.IO to communicate with an external service (Drupal, Joomla, Wordpress, whatever):
1) Making a rest API for your Socket.IO application (for example using Express for the API layer and then passing messages to Socket.IO with an EventEmitter).
2) The better solution in my opinion is to use a message queue like Redis, RabbitMQ or ZeroMQ. The Drupal website would send a message down the channel to Socket.IO and then Socket.IO would send that message to the client(s).
If you are creating a system that needs authentication also, I suggest you don't let your users send message directly with Socket.IO, but make an Ajax call to your main server instead (Drupal for ex.). That way you can check the user's identity more easily. (This scenario would be a fit for a chat based system that requires authentication)
Although this video tutorial is for EventMachine with Faye, the same logic could apply to your app: http://railscasts.com/episodes/260-messaging-with-faye

Non browser based websocket clients in PHP

I was looking at Kanaka's reply to a websockets question here.
If I want to write a native app in PHP to use a websocket based webservice, where do I start? Are there any client libraries available in PHP to write native linux clients?
Basically, my server can work on a RESTful architecture for 90% of the time. However, there is one reason for the server to alert the client, so REST won't work here. So I am wondering if websockets is an answer here for me as compared to periodic polling by client.
Why not write the 90% using normal REST and do the remaining part where notifications are sent to the client using web sockets?
Here is a github project that looks like it might be what you want https://github.com/nicokaiser/php-websocket

Categories