0

I have a website written in php. Till now I used setTimeout with ajax to update chats simultaneously but after that didn't work I learnt about socket.io. I need to implement private messaging and I have got some things covered in socket.io but when I ran it on localhost I had to keep the terminal open as long as I wanted to chat.
1. How am I supposed to do that on my server which is Hostinger currently. Is there some terminal I need to run or do I need ssh(shell) access which I don't have at the moment?
2. If there isn't, how would the node script keep running?
3. And since socket uses node, how would the app use node modules? Do they need to be uploaded to the hosting space?

Apart from that, if there is any private messaging and group messaging implementation anyone knows about even other than how it could be done in socket.io it will be very helpful if you could suggest. I need the users to chat among themselves not with me.
Thanks in advance!

Vipul Sharma
  • 525
  • 9
  • 23
  • You likely can't run this on any shared hosting provider, either by limited access or limited terms of service. You could look into a third party service like Pusher. – Devon Bessemer Nov 05 '18 at 12:48
  • @Devon I already looked into Pusher but as far as I know they do not save messages more than 30 days. If it is so, that doesn't sound good. – Vipul Sharma Nov 05 '18 at 12:51
  • Why would you need messages saved on a socket service? – Devon Bessemer Nov 05 '18 at 13:05
  • @Devon Because they are my users's messages. Mine is a social network, so users can see their previous chats as well. – Vipul Sharma Nov 05 '18 at 13:36
  • Previous chats have nothing to do with sockets. Use a database for that.. Sockets are for the real time message updates. – Devon Bessemer Nov 05 '18 at 13:45
  • @Devon It seems like Pusher has many limitations like file size and a limit on users and number of messages. Do you think of some other way? – Vipul Sharma Nov 05 '18 at 14:01
  • Host your own socket.io server. You just won't be able to do it on a shared hosting account, you'll need a virtual machine or dedicated server. Pusher seems affordable for what they offer. If you have more than 100 concurrent users, don't expect anything free. – Devon Bessemer Nov 05 '18 at 15:47
  • For node script keep running, follow this article https://stackoverflow.com/questions/4681067/how-do-i-run-a-node-js-application-as-its-own-process/28542093#28542093. But again for this you need dedicated hosting or Sudo access of your server. – Vitthal Nov 07 '18 at 07:01

1 Answers1

2

You can do this by using node js ,socket.IO and express.js

Link given below can provide you with a rich documentation to reach a solution.

https://socket.io/get-started/chat

For running your application in background you can use PM2 process manager.

For documentation refer below link

http://pm2.keymetrics.io/

Vipul Sharma
  • 525
  • 9
  • 23
Vitthal
  • 127
  • 7