• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can i build websocket application using codeigniter

#1
Hello guys ,

i want to build a web socket (ex : socket.io) application for a real time data ( chat with group of people )

how could this be accomplished using codeigniter  ?
Reply

#2
Codeigniter cant do this out of the box. You can include a library like http://socketo.me/ that can do this or take a look at this projects

https://github.com/ranchor/socket-node-m...ter-chat-1
https://github.com/llbbl/codeigniter-chat

Reply

#3
It's important to realize that HTTP requests are accomplished by making a socket connection. The basic idea is that a client (e.g., a web browser) opens a socket connection, usually on port 80 (usually port 443 for HTTPS), to a web server and then uses that socket connection to request data from the web server using the HTTP protocol. E.g., it might send a request "GET /path/to/file.html" over the socket and the web server would respond by coughing up the html document. Depending on server and client configuration and the connection details, the client may request more files like images, CSS, and JS files before closing the socket connection.

Now if you are clever, you'll realize that by the time CodeIgniter comes into this scenario, the connection has already been made by the client to the web server and the web server runs your codeigniter code in response to the request. Basically, the socket connection has already been made and its waiting for a response from CodeIgniter over the open connection.

Within CodeIgniter, you might be able to create a new socket using socket_create_listen but this socket will only last as long as your CodeIgniter script is running. Once your script ends, the socket it created is likely to be closed and cleaned up during the garbage collection process-- unless you find a way to fork off a separate process form your code igniter script. You probably wouldn't want to fork off a process from your CodeIgniter system that opens a listening socket in response to many visitors coming. You might want to do this for a script accessible to administrators only. This sort of action is similar to rebooting a mail server or web server or firing up some kind of persistent service.

Another possibility is that your server might try to open a socket connection to someone else. A client might connect and say "hey my ip is 12.34.56.78 I want you to connect on port 1234" and then your server could use socket_connect to try and connect to the client but this in practice won't really work all that often because most users will be behind a firewall or a wireless router or something which is not set up to accept incoming socket connections on arbitrary ports. It takes a bit of know-how to set up NAT on one's LAN and you typically need a fairly capable router.

CodeIgniter *could* be used as a way to start/restart/reload/halt some kind of socket server on your web server, and CodeIgniter *might* be used in the construction of a socket server, but it seems quite awkward to me. I wrote a socket server in PHP called FlashMOG some time ago but haven't updated it in years.
Reply

#4
(12-24-2014, 04:54 AM)Rufnex Wrote: Codeigniter cant do this out of the box. You can include a library like http://socketo.me/ that can do this or take a look at this projects

https://github.com/ranchor/socket-node-m...ter-chat-1
https://github.com/llbbl/codeigniter-chat

Hi Rufnex,
I am using ur thread "https://github.com/ranchor/socket-node-mysql-codeigniter-chat-1" for chatting in codeigniter. And it's perfectly working with mysql but i want to integrate it with POSTGRES. So please help me to integrate it with POSTGRES.
Thanks.
Reply

#5
(12-24-2014, 04:54 AM)Rufnex Wrote: Codeigniter cant do this out of the box. You can include a library like http://socketo.me/ that can do this or take a look at this projects

https://github.com/ranchor/socket-node-m...ter-chat-1
https://github.com/llbbl/codeigniter-chat

Awesome! Thank you! Big Grin
Reply

#6
(01-20-2015, 12:57 AM)sachin205 Wrote:
(12-24-2014, 04:54 AM)Rufnex Wrote: Codeigniter cant do this out of the box. You can include a library like http://socketo.me/ that can do this or take a look at this projects

https://github.com/ranchor/socket-node-m...ter-chat-1
https://github.com/llbbl/codeigniter-chat

Hi Rufnex,
I am using ur thread "https://github.com/ranchor/socket-node-mysql-codeigniter-chat-1" for chatting in codeigniter. And it's perfectly working with mysql but i want to integrate it with POSTGRES. So please help me to integrate it with POSTGRES.
Thanks.

Just change your database configuration to postgre

db['default']['dbdriver'] = 'postgre';

And create the needed tables.

Reply

#7
Handling realtime events properly is very hard and there is a lot of things to think about.

Quote:Vital for any production deployment, should be considered when choosing a real-time web technology including:
  • Vertical scalability (and performance in general)
  • Horizontal scalability via fault-tolerant clustering
  • Guaranteed delivery of data in presence of failures (e.g. if the connection between a client and a messaging server is broken or if the messaging server serving the client goes down, the client will reconnect to another cluster member and will receive all messages published during the reconnection time)
  • Security of data including data entitlement
Source: http://www.leggetter.co.uk/2013/12/09/ch...stack.html

Most of the stuff in above quote applies for large scale project and services, but anything can grow and you might end up with issues pointed out above.

This website is a good resource for information, what to think about and available services and libraries out there.

I always recommend these days to use services that can take care of all the "issues" for you, so that you can spend all your time on building a better experience and website for your users.

I personally have experience with Pusher Realtime service. It starts as free and goes up to enterprise level. It works nicely with CodeIgniter as well and I have created a library that anyone are welcome to use for any project.
Reply

#8
Hello everyone,
Here I try to create a websocket (PHP Ratchet) application integrated with CodeIgniter.
Please take a look, I think you find it useful.

https://github.com/kishor10d/CodeIgniter...-Websocket

Please visit the link and download the repository.
Reply

#9
(12-24-2014, 04:54 AM)Rufnex Wrote: Codeigniter cant do this out of the box. You can include a library like http://socketo.me/ that can do this or take a look at this projects

https://github.com/ranchor/socket-node-m...ter-chat-1
https://github.com/llbbl/codeigniter-chat

Can anyone help me to run "https://github.com/ranchor/socket-node-mysql-codeigniter-chat-1". I'm not good in socket and all, so once I enter the name press join room it shows like the attached file.

So please help me to solve this issue. Thanks


Attached Files Thumbnail(s)
   
Reply

#10
(09-19-2016, 12:50 AM)kishor10d Wrote: Hello everyone,
Here I try to create a websocket (PHP Ratchet) application integrated with CodeIgniter.
Please take a look, I think you find it useful.

https://github.com/kishor10d/CodeIgniter...-Websocket

Please visit the link and download the repository.

is this working without angular?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
2 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.