Welcome Guest, Not a member yet? Register   Sign In
how to implement Server-sent events with codeigniter ??
#1

[eluser]Unknown[/eluser]
hi ,I'm working on a project,i need to refresh page automatically when a function in my controller be called,please if you have something to help me to implement Server sent events in my project.thank u
#2

[eluser]TheFuzzy0ne[/eluser]
It's certainly possible, but you'd be better of using a different protocol, like IRC or Jabber. HTTP (at the moment, anyway), doesn't allow you to PUSH requests from the server because there is no persistent connection to the server.

You can set up your server to allow a persistent connection, but it's probably easier to just set up polling, which would require Javascript. Then you send an AJAX request to the server every n seconds, and the server can let you know if anything's changed. It's up to you to implement your backend so that it keeps a record of when your controller method was last called, which can be queried easily. Just bear in mine that this will require Javascript to be enabled in your users' browsers.
#3

[eluser]Unknown[/eluser]
I thinking about send an AJAX request to the server every n seconds,but the problem with this ,if i have a lot of connections in real time with the server,my server will be under presure .
#4

[eluser]Pert[/eluser]
[quote author="lorenzo108" date="1369837585"]I thinking about send an AJAX request to the server every n seconds,but the problem with this ,if i have a lot of connections in real time with the server,my server will be under presure .[/quote]

Depending what did you mean by a lot of connections.

If you have one page that has multiple parts updated, you can do one call every 5-30 seconds and it will get data back for all the different updates.

If you mean you have a lot of users then doing a AJAX request should be less straining on the server than all these users hitting F5 all the time, as there should be much less data going up and down.

For medium size projects (number of users, posts, etc) you will get away with well planned application structure to minimise work and calls that server has to do.

If you are planning to build Facebook, I believe they keep all the updates in RAM rather than DB.

Said that, Facebook started as standard PHP site without massive server farms and custom built server software.




Theme © iAndrew 2016 - Forum software by © MyBB