I'm new to websocket and realtime applications and I would need some clarifications.
I developed an application for a customer that involve some users and product data.
It is a PHP web application running on the internal apache server.
The client side of the app is based mainly on JQuery, and for some parts usable from tablet devices we used JQuery mobile / html5.
Now the customer is asking to add some messaging/notification feature in this way:
a user will be able to post a message about a product and the web console of the other users must be "showed" a realtime notification. We are thinking to add something for example in the header of the page to notify that new messages are present.
I made some research and as all the app is already built in PHP I was thinking to go for Ratchet. Is this a good idea?
If I understood this well, I will need to install on the server also the ratchet server components and use for client side integration something like AutobahnJS library; is it right?
Has anyone already built something like this?
Is there any problem communicating between Apache and Ratchet server?
That okie,
I tried use Ratchet/AutobahnJs Websocket, that's awesome. But I have (special?) problem :o in here.
In your case, I think you can use AJAX, it's simpler than Websocket. You can "zip" multi-notifications in to 1 response and request server every 5 seconds.
Yeah it's a good way to go about it, ajax leaves you with a lot of overheads. it's pretty simple to get going with ratchet and it will give you the ability to send notifications in real time, as well as the notifications it will allow you to edit the page as well, i.e change counters/ icons / message count etc, basically same as ajax only in realtime and no need to poll for new data.
It also means you'll be learning some new stuff which is always a bonus, for this alone i would do it.
Related
I need some methods for pushing JSON messages to android application from the server using PHP but without GCM or FCM.
I don't want to use Google because it sometimes doesn't send messages or they arrive in late, and I need a reliable service.
My goal is to update some text views when something happens on the server, for example, a user subscribes for a live game, so other users see the number of players increased real-time.
Also, I'm a little ashamed, I'm not able to use other server languages except PHP, and even if I could, my hosting service is not able to install Node or other languages. Moreover, my hosting server doesn't support the composer, so I need to install libraries manually.
I try to use Pusher, and it works fine, but it costs too much if one day I reach a good number of players. Actually, my budget is 0 :(
I also heard about Socket.io but I don't know how to use it with PHP. If someone uses it with PHP I'm really happy to see a front-end and back-end simple examples.
Does anyone have a solution?
Your use case would be best served with something like Firebase Realtime Database or Cloud Firestore or if you want your own server stack, something like Parse.
Doing this will avoid the use of server side code. Also you can react to real time changes with all of the above. All these intrinsically do run over Sockets so instead of rolling out your own, i suggest you have a look at these and try to fit these for your use case.
Using notifications for this is kind of an overkill and may cause your app to get blacklisted for overly spamming users.
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.
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
I was trying to develop a web based chat system using PHP. I created one with the combination of jQuery and PHP but this setup is using lot of network bandwidth as it is continuously sending / receiving data to check whether a new message has been received or not (currently every 1 second). So I need to develop a system that will automatically display the message once a message is received from the other end without the need of sending a request to the server to see if there is a new message received.
I read in many places that this can be done using Jabber. I am really new to this jabber technology, so any help creating a new Jabber based chat using PHP will be greatly appreciated.
Jabber (also known as XMPP) is more of a protocol, so it's not really the solution you're looking for.
HTML 5 web sockets are a great new technology to achieve this. Rather than polling to see if there are any messages, the server can "push" new messages to the browser.
The client side code is JavaScript. The server side can be anything implementing the web socket protocol. There are probably some PHP libraries to write the server side code, but I have written a few Ruby web socket servers using EventMachine and em-websocket.
let me introduce my story first. To develop a multiplayer network game in facebook, flash used to be a king but it consumes a lot of resources for client and I feel like it isn't worth for a card game. So I come with an idea that front-end will use Javascript (of course with jQuery) and backend with PHP. But for real-time communication, it isn't possible just with PHP and Javascript. It doesn't make sense to record every movement of players in MySQL and display back to another browsers. So I come with an idea with XMPP Services. XMPP services can even communicate browser to browser and display contents with Strophe and Javascript even without with PHP.
Finally, I've got every tools I need but I have few questions that I can't answer myself.
1) How XMPP server work between PHP and Javascript? I need to get/post user records from MySQL and calculate movements then forward results to intended user. There will be an Authentication system too so that's gonna be taken care by PHP as I'm not wrong.
2) This question is the title of this post.. Is it possible to run XMPP based PHP and Javascript Multiplayer Network Game in FaceBook?
Thanks in advance for all of your time and advices!
The connection would work using PHP sockets, and you could easily use Ajax to send data to PHP to send on to the XMPP server. There are also a number of libraries for communicating with XMPP servers using PHP. As for Facebook, it shouldn't have any effect on your script - if I remember correctly Facebook runs your app in its own sandbox so you shouldn't have to do anything special to get around the Facebook API.