Recently I started working on web applications. Sorry if this is silly question.
I had an Android app earlier. I was using GCM for push notifications. Recently I have developed a web app using PHP for this application. I should notify the user when he receives new messages,alerts etc..
I read many blogs and learned that using WebSockets is the good solution.
So my question is
Is using Websockets a good solution ? Do I have any other good alternative?
How to use WebSockets here? Do I need to send request to Apache server for every interval after user login ? If yes what is the recommended value for interval? (please help me with sample example if possible)
Can I use WebSockets in shared hosting?
Related
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/
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?
I tried searching these issues. Some sites say I need to do some stuff with php in order to make 3rd party server while others don't mention anything. some says it need JSON. Guide me please. PS I am a beginner and know java, XML,SQL only.
You should only need one server. The second server you are reading about may be the Google GCM cloud server? When I did a GCM project a few years ago, I had one server, it happened to be a App Engine instance. It generated events and sent them to Google via the GCM api and then onto onto the device. I don't remember it being that difficult.
I did have more than one server in the mix though, there were others that sent messages to the AppEngine server, but it was not required to send a GCM message.
Google Cloud Messaging (GCM) is a service that enables developers to send data from servers to both Android applications or Chrome apps and extensions.
So if you want to send data to the users of your App then you must have an interface or dashboard from where you can send some data (typically push notification) to the users of your app.
This dashboard (server from which you can send data) can be developed by using PHP or any script languages.
Now a though can come up in your mind:
"I am suppose to develop both the mobile app and the server then what
role does GCM play?"
Yes, GCM is playing a vital role indeed. The server we have to develop is just to design an interface so that you can type your message/notification and select the recipients. Rest of the part of (managing the queue, communication with the apps checking for authentication and all other stuffs will be done by mighty GCM )
In order to have an bird-eye overview you can take a look on this image collected form android hive
Server side coding is doesn't need you to be expert in php. So you can go through to this article. It helped me a lot to learn.
I am currently building a SNS for both web and iphone/android applications.
When an user writes on the wall or leaves a message, the server needs to push notifications to all related users. Users who are logged in on PC will receive it via Socket.io and those who are logged in on iPhone or android apps will get it via GCM/APN.
What is the best way to send push notification(GET) to all these users from a php web server?
cURL seems to do the right work but is extremely slow on my server.
The web server will need to send notifications to at least 3 different servers at once at unnoticeable speed.
Any suggestions?
I'm in the process of building such an application and I have to be honest and advise you to use Zend Framework. There is also a lot of database planning to be done as read/writes to and from a database will be high. Specifically use Zend_Mobile or visit my blog for the gcm solution http://www.rogerethomas.com
Ideally you should run a cluster of servers processing messages and queues. Push messaging can get out of hand quickly and taking the time to plan it properly will pay off I promise you.
I need to make chat application for android. I thought of using PHP script to implement the chat application. Basic idea is to send message form android client to PHP script and making use of PHP script send the messages to the MySQL database. These messages will be broadcasting to other people. But the problem is auto broadcasting messages to other people. Is there a way to do this using android and php?
You can do the following
Make a persistent tcp connection between your device and the PHP server
When a message is broadcast send it over the tcp connection of each device
On the device process this notification and you are good to go.
If you want to use Java on the server side I have your project already finished and ready to ship ;) (just kidding)
But if you are interested check out the Device-To-Device messaging framework of OpenMobster Mobile Cloud platform. The project is free and open source. Here is a link to the Device-To-Device Framework: http://code.google.com/p/openmobster/wiki/D2DPushFramework
and http://code.google.com/p/openmobster/wiki/PushFramework
The above three steps are already taken care of by the framework. The developer just has to focus on the App itself
Good Luck!!!!
Yes there is several ways to do this
you can just post to the server and from the server send push notifications to the mobiles
You can make the mobile keep checking for updates if it exists
You will require to finish these steps ( at least ):
setup a PHP web server
register for Android Push Notification (you probably need that)
create database schema
write your own codes to allow users to submit & retrieve chat messages
security !!!
You'd probably want to use Google's C2DM, though it's not free.
Your php server would get a message from a phone, do it's processing, then make a HTTPS request to Google's C2DM service, which sends the messages to the destination android device.
http://code.google.com/android/c2dm/#push-process
Don't use C2DM, its a deprecated. Please go through the GCM(Global Cloud Messaging),
please follow this link,
http://developer.android.com/google/gcm
Have you heard of Firebase? Firebase. Making a chat app with Firebase is like eating pizza.