Auto highlght the table row if status change from admin panel - php

I have one application which has admin panel and user panel in laravel.
What i need that when ever user approve any record set from adminpanel that row on user panel should change its color or notify it automatically for some time then this change has occur.
I am not in mood to use ajax calls running continously on the page

WebSockets are used to implement realtime, live-updating user
interfaces. When some data is updated on the server, a message is
typically sent over a WebSocket connection to be handled by the
client. This provides a more robust, efficient alternative to
continually polling your application for changes.
To assist you in building these types of applications, Laravel makes
it easy to "broadcast" your events over a WebSocket connection.
Broadcasting your Laravel events allows you to share the same event
names between your server-side code and your client-side JavaScript
application.
Check Laravel Docs

Related

Implementing Real Time application using Redis and Faye

I need to develop a realtime notification system. Load won't be high, about a dozen of events per hour. But I just want to make it scalable for future development.
My application is written entirely in PHP.
I have found different ways of implementing real-time applications. And I think the following architecture is quite simple and have a lot of benefits.
But I want to use the Faye library for implementing real time notifications, because it has fallbacks, and generally I am not going to use Websockets because my load is really low, and at first I will stick to the long-polling mechanism. Faye provides a convenient way for disabling and enabling different transport protocols.
Here is how my architecture is going to look
However I have one question regarding communicating back from a client.
Consider the following case.
Client loads a page through plain old HTTP request to a PHP app
Client side script opens a websocket/long polling connection
Another person sends notification via posting it through a simple AJAX request
This notification is saved to a database and assigned to a target recipient.
Notification is posted to a Redis database and consumed by Faye
Notification is sent to a client, everything is fine.
So far so good, but I need to some sort of back communication, for example when a client dismisses an event.
How should this be implemented, should I send this action back using Faye or this should be sent directly to the PHP application. In case of sending an event back using Faye I need to notify my PHP application that an event was seen and dismissed. Of course I can use the same database from a Ruby application as used by PHP app, but this makes these two application coupled.
Could you suggest a right way to implement this ?

Update total number of registered user count without page refresh

I am making some Real Time data application and I want display total number of user registered to my site.
The count should refresh automatically whenever a new user registers without refreshing page.
How can I achieve this?
I am using php, Laravel and MySQL
You can use Laravel's Broadcasting, Laravel supports redis and pusher by default.,
Configuring Broadcast
There are set of configuration in config/broadcasting.php, just add the required configurations in the file directly or through .env
Before broadcasting any events, you will first need to register the app/Providers/BroadcastServiceProvider . In fresh Laravel applications, you only need to uncomment this provider in the providers array of your config/app.php configuration file.
I personally using Pusher service, you will get a PUSHER_APP_ID, PUSHER_APP_KEY and PUSHER_APP_SECRET.
Configuring Laravel -Echo (Js - to receive the broadcast)
while using pusher, use laravel-echo js to listen for events broadcast by Laravel, you can install through npm install
npm install --save laravel-echo pusher-js
In your app.js just add this to import and initialize the Echo and store in a window object
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'your-pusher-key'
});
Sending Broadcast
when defining broadcast events there are three different methods available broadcastOn, broadcastWith, broadcastData. Broadcast by triggering the event
event(new youBroadcastClassName($array))
Receiving Broadcast
Echo.channel('channel-name')
.listen('youBroadcastClassName', (e) => {
console.log(e);
});
now it is available in the js you can use some js functions to show in the front end.
In your case once user is registered trigger the broadcast event with data which you need in front end, just receive in the js and populate it in the view
Go through this link Laravel Broadcasting
EDITED:
What you need is called Broadcasting. You need to implement 2 things
Subscriber: at your client's side, connect to your websocket server
Publisher(your websocket server): at your server's side, waiting for any subscriber's incoming connection
The basic idea is when you register an user, if succeed, at this time call the Publisher to send a message to it's subscribers to update the user count.(just like when you subscribe to someone youtube channel, when they upload a new video, you get a notification)
you can use https://socket.io/ to implement your client side
Laravel supported it also, find the Socket.io section laravel
Use brodacasting feature.
In many modern web applications, WebSockets are used to implement realtime, live-updating user interfaces. When some data is updated on the server, a message is typically sent over a WebSocket connection to be handled by the client. This provides a more robust, efficient alternative to continually polling your application for changes.
To assist you in building these types of applications, Laravel makes it easy to "broadcast" your events over a WebSocket connection. Broadcasting your Laravel events allows you to share the same event names between your server-side code and your client-side JavaScript application.
WebSocket absolutely the correct answer for this question. But for beginner I think you can always use setInterval and good old ajax.
I am not saying this is the most correct answer, but this would be much more simpler and easier.

Laravel 5.1 Session and Socket.IO + Redis - Sending Notifications to Logged In (Known) Users and Group Of Users

I am working on a project where I want to implement real-time notifications for a specific group of users (with role of Admin) and after some research, I understood that I'll need the session in order to know which users are logged in (by default they are anonymous).
Also, I'll need to implement notifications to specific users only. (only one user, example: John Doe)
So, my questions are:
How can I transfer the session/cookie over to the NodeJS side through Redis and then emit the notification?
What should I do exactly?
Any encryption / decryption?
Anyone ever had any chance to implement anything like this?
There's almost no info about this on the internet and most of the tutorials are way too basic for my use case.
I am using Laravel 5.1 Broadcasting features to publish some notifications and display them in real-time with Socket.io (version 1.3.7). I also use Redis (version 3), NodeJS (version 5) and Express (version 4.13).
Thanks for reading!
I've been implementing (slowly) something similar for a web app using Autobahn and WAMP, it's associated protocol and router. I currently have about five different services (some written in PHP, some in NodeJS) plus the clients all communicating in real time.
The nice thing about WAMP is that it encapsulates both remote procedure calls (RPC) and publish/subscribe (PubSub) models for communication.
My authentication scheme is a bit of a kludge: on each page of the Laravel web app, there is a token value which is unique to the user and generated upon log in to the Laravel app. The Javascript uses this token value to authenticate when the client connects to the WAMP router - if it's an invalid (or stale) token, the connection is refused.
As for limiting notifications to specific users or groups, one simple way to do it would be to wrap the appropriate JS code in a function that is only called (or is only output to the client in the blade template) if the user has the appropriate permissions.
Finally, my application is strictly for use inside our firewall, so I haven't investigated using encryption/decryption.

Using Redis to communicate between PHP and socket.io/node.js

I have a PHP app built and running on Apache, using Nginx as a reverse proxy to serve static resources.
I also have Redis installed which I am using to store activity ID's for each users activity stream. The activity gets written to a MySQL database, then Redis pushes the activity ID into each users stream. When a user receives his/her activity stream, the app first retrieves the users list of activity ID's from Redis and then gets the actual activity data via a MySQL IN() query.
This all works very well, however I want to start add real time capability to this set up. I would like to be able to push these events straight to a users browser and also add general live notifications.
For this I have installed node.js with socket.io. I have the socket.io server correctly up and running and a client is automatically connected on page load.
Where I am struggling is in understanding how to post a message to socket.io from within my PHP app. Since PHP and node.js cannot communicate directly, my understanding is that I would be best off utilizing Redis as a go-between since I already have it installed and up and running. However I have no idea how to go about this.
What I need is a description of the process (any code examples would be very helpful) of sending a notification from PHP to Redis and then into socket.io in order for it to be pushed to the relevant client.
Also, I do not understand how socket.io would know which client to send to. How would I pass this information along and keep everything synced? Is this even necessary? Do I need to store my PHP sessions in Redis and have socket.io collect the data when a user connects? Or is there another way?
Thanks in advance.
Please Note: My PHP SESSION data is currently saved to disk.
You can set up a pubsub channel on Redis (please see http://redis.io/topics/pubsub). Then subscribe to it from your node.js process. Your PHP would then publish to pubsub to communicate to the node. You can have separate pubsub channels for different clients and publish to whatever channels you need to reach your specific clients.
Redis doesn't offer inbuilt websocket or http server so we have to integrate it with php or node.js in order to stream channel data. with Tweak method, we can connect Redis server with php using predis php library for redis, where php will push data into Redis and socket.io will keep track of new messages pushed into Redis sever and beam it back to users connected to it in real time.
https://github.com/u-day/tweak/

How to use Magento's API asynchronously without OAuth?

I'm working on integrating a Magento store with an existing desktop Point of Sales software. My idea is that this desktop program would connect through Magento's REST API to gather the product list, inventory changes, etc., and it will also commit new products and other updates through the API endpoint.
The problem arises when I don't want the person in charge of the PoS know the API credentials or don't want to bother prompting for them. The best would be to set them up in a config file.
I thought about loading the API authorize page in the background and automatically post the credentials to the login form. But this looks like a nasty approach.
Any ideas?
Not a solution but some words of experience in this matter...
Magento's API can be slow and the user will wait forever for the task to finish especially if the server is under load. We use another application which uses the Magento's SOAP API which I built using java to handle all updates/downloads between magento and our POS. This way the user is not waiting on slow responses, or stopped by loss of connectivity.
We have adopted your queue approcach, and another reason for having 1 application with a queue is that it handles all updates from all users and Only Allows 1 Task To Execute At Once. You need to do this to avoid database locks. e.g. Two users modify a product and you get a table lock error and the update fails. You can also overload the server by flooding it with lots of single user requests to the server. We still have event driven processing as opposed to synch scripts by having our POS send messages to our local app instructing the app about the task and it simply queues the task for processing. Our application has no user interface what so ever and I run it as a System service on our server, with the user credentials stored in a config file.

Categories