Welcome Guest, Not a member yet? Register   Sign In
WebSockets in PHP/CI/jQuery
#1

This question isn't completely related to CI framework, but I hope to use CI for it, and I believe theres a lot of bright individuals here, so ill ask!

I have plenty of instances on my CI application where I use AJAX to monitor for any changes on something, and update it when changes are found. While this gets the job done, obviously theres plenty of downsides of throwing an AJAX request in some type of loop.

I was looking into the idea of using WebSockets instead, using PHP and jQuery. I had a question about the server side...

The "Server" that the WebSocket connection connects to, is it possible to have this in a CI controller, served through Apache/NginX? Or does it have to be a stand alone script running in the background.

If its the latter, them I'm just curious if anyone here uses WebSockets, and how they get it done. In all the examples, you have to launch the PHP script as the server via the command line, so if this is in production, how do you do that? Does it have its own init script to start it as its own process? How does it get launched? Id prefer if the jQuery just made the connection right to the VirtualHost instance, but im not positive thats how its done.

Thanks
Reply
#2

(10-26-2015, 10:34 AM)jLinux Wrote: This question isn't completely related to CI framework, but I hope to use CI for it, and I believe theres a lot of bright individuals here, so ill ask!

I have plenty of instances on my CI application where I use AJAX to monitor for any changes on something, and update it when changes are found. While this gets the job done, obviously theres plenty of downsides of throwing an AJAX request in some type of loop.

I was looking into the idea of using WebSockets instead, using PHP and jQuery. I had a question about the server side...

The "Server" that the WebSocket connection connects to, is it possible to have this in a CI controller, served through Apache/NginX? Or does it have to be a stand alone script running in the background.

If its the latter, them I'm just curious if anyone here uses WebSockets, and how they get it done. In all the examples, you have to launch the PHP script as the server via the command line, so if this is in production, how do you do that? Does it have its own init script to start it as its own process? How does it get launched? Id prefer if the jQuery just made the connection right to the VirtualHost instance, but im not positive thats how its done.

Thanks

Hey you want to look at using http://socketo.me/ it handles sockets for PHP there are a handful of tutorials on the web related to it too Smile
Reply
#3

(10-26-2015, 11:24 AM)mlantz Wrote: Hey you want to look at using http://socketo.me/ it handles sockets for PHP there are a handful of tutorials on the web related to it too Smile

Actually, yeah, thats the one I'm working with now.

Still leaves the questions I asked unanswered though. Most of these are stand alone examples. Im mostly wanting to know if its possible to just have the JS open a WebSocket connection to a CI resource on the main website, which is just an Apache vhost, or do I have to have a separate script executed via the CLI, running in the background.
Reply
#4

One last bump?
Reply
#5

(10-31-2015, 08:19 PM)jLinux Wrote: One last bump?

hi, i just meet the same problem with you ,so have you solved the problem yet??????
Reply
#6

(This post was last modified: 03-29-2016, 11:22 PM by arma7x.)

Here the implementation, https://github.com/kishor10d/CodeIgniter...-Websocket. This library is not mine and I'm not try it yet.
Keep calm.
Reply
#7

i know this thread is a little old but I have some input.

I've gotten websockets to work with codeigniter using react but at the end of the day, it just wasn't suitable. I found myself constantly running into issues and it was more of a headache than anything.

I switched and tried creating a Node.JS app and and Elixir app and have been successful in both. Both are much easier to work with (Node probably moreso than elixir.)
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#8

(03-29-2016, 11:19 PM)arma7x Wrote: Here the implementation, https://github.com/kishor10d/CodeIgniter...-Websocket. This library is not mine and I'm not try it yet.

@arma7x :

I know that its kinda late reply, but yes, it my library.
Previously I done all implementation with AngularJs, PHP Ratchet Websocket with CI.
And before some days, I added the separate code for jQuery too instead AngularJS.

Please checkout.
Note : The library will work on server if you have dedicated server or having ssh access (wheel user group). Otherwise you can test the implementation on local, it will run smoothly.
Reply
#9

Hei guys. I am very interested in this topic. I have tried node.js in heroku and it seems pretty nice. A couple of doubts:
1) In terms of performance websockets are more resource intensive for the server then normal http request / responses ?
2) In terms of the application itself, do you think it's easier or harder to build with websockets? Or maybe it doesn't even make sense to use websockets I dunno... For example, blog, institutional website, ecommerce, and so on...
3) What are the best scenarios to use websockets? I am not sure if websockets are here to completly dominate or if they are resource intensive and should be used for real time applications or widgets... for example... maybe use a webchat that will be in an iframe inside your normal website?

I would love to be more enlighted on this... I have made a simple chat application on heroku with a couple of lines. It is super effective in terms of code and performance for the user... I don't know about the server though...
Reply
#10

(08-15-2016, 11:52 AM)Ivo Miranda Wrote: Hei guys. I am very interested in this topic. I have tried node.js in heroku and it seems pretty nice. A couple of doubts:
1) In terms of performance websockets are more resource intensive for the server then normal http request / responses ?
2) In terms of the application itself, do you think it's easier or harder to build with websockets? Or maybe it doesn't even make sense to use websockets I dunno... For example, blog, institutional website, ecommerce, and so on...
3) What are the best scenarios to use websockets? I am not sure if websockets are here to completly dominate or if they are resource intensive and should be used for real time applications or widgets... for example... maybe use a webchat that will be in an iframe inside your normal website?

I would love to be more enlighted on this... I have made a simple chat application on heroku with a couple of lines. It is super effective in terms of code and performance for the user... I don't know about the server though...

1) http://stackoverflow.com/questions/14703...ol-vs-http
2) Depending on user experience or you can try using Sailsjs. As I know, paypal using nodejs(backend)
3) Maybe realtime webapps or SPA.
Keep calm.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB