PHP websocket documentation - php

I love programming using PHP. Recently I've wondered wether to spend more time learning node.js or not. Then I stumbled across PHP websocket. I saw an example making a live chat in websocket, where messages was sent in live time.
However, I can't seem to find any documentation or, better yet, explanation of what this feature actually does! Can anyone explain what PHP websocket does (technically), or send link to the correct documentation?
Wouldn't PHP websocket make it possible to push any type of content in real time to users, just like node.js can? Or have I misunderstood?

WebSockets are a bi-directional persistent connection from a web browser to a server. Read WebSocket on WikiPedia and Mozilla Web Docs
node.js and WebSocket are 2 different things. node.js is programming language built on the Google V8 JavaScript engine, whereas WebSocket is communication protocol.
Yes, WebSocket can help you push real-time updates to your client.
Here is One of the site that can help you work in WebSocket using PHP - http://socketo.me - Documentation URL : http://socketo.me/docs/

Related

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.

can a regular webhost and a separate node js server communicate?

I'm currently working on a trade / social network site as a side/learning/fun project.
At the moment I have an sql database messaging system. I want to create a live chat system like facebook which can tell the user is online, typing a message and everything.
I did some research into this and figured I need to start learning to use node.js and websockets. I called my webhost and they said they don't support node.js. I like the tools I'm using and do not want to migrate my website.
I also looked into some info about CORS.
I was thinking of a solution: client as well as the php server also communicates with an external node.js server using jquery to handle all chat and notification requests. The node.js server will also store messages in the php servers mysql database.
Is this solution feasible and am I on the right track? Or is there a better way?

iOS + Laravel - Turn Chat Feature Into Web Socket

I have a chat feature in my app using JSQMessagesViewController (https://github.com/jessesquires/JSQMessagesViewController).
It makes an API call to my server every 5 seconds to get all the chat messages between two users to populate the chat view with those messages. It was suggested I turn that into a socket connection because making an API call every 5 seconds will be hard on the battery and a waste of API calls.
How do I turn my chat feature into a socket connection with my server?
Are there any libraries in Objective-C that will help me accomplish this? And also, I'm pretty sure that I'll have to set this up on the back end too, so are there any resources as to how to set this up on a PHP Laravel backend?
You should be able to accomplish this using a couple mature libraries on both the iOS frontend and the PHP backend.
iOS: SocketRocket
https://github.com/square/SocketRocket
PHP:: Ratchet
http://socketo.me
They both support RFC 6455 so should integrate pretty easily.
Since you are using PHP, I'm going to take a stab and guess you are using Apache? If so, here is some more information on setting up websockets to work with Apache which can have issues with connection management: Setting up a websocket on Apache?

WebSockets basics and PHP

I have been researching WebSockets for a few hours but can't seem to understand why you would need both client and server side libraries to help with WebSockets implementation?
I am using PHP so from research it seems like Ratchet is the most popular. But why would you need a server side implementation of WebSockets when server side HTML5 supports WebSockets? Can you build a chat system without the use of libraries at all? And can you build a chat system, for example, without any support on server-side, i.e. just with a jQuery library?
And how does WebSockets relate to node.js? I find it hard to get to grip with server side running JavaScript to send responses to a JavaScript front end.
Also, is this: https://code.google.com/p/phpwebsocket/ library a similar thing to Ratchet?

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