FreiChat related discussions
Comet vs. Short Polling

Hello,

I saw in the backend section, Advanced - Polling, that one can choose between two types of message handling. Till now I used Short Polling, and I wanted to try to use Comet, to see what the performance would be. However, if I select Comet, as Polling Type, nothing changes. Still requests each 5 seconds. Does Comet work? Is that based on HTML5's Server Side Events (eventsource)? I think it would save resources.

Also, I am not sure if I understand the text on that page. Should the pros and cons for the two types be switched? That the pros and cons of one belong to the other?

Greets

Hello, I saw in the backend section, Advanced - Polling, that one can choose between two types of message handling. Till now I used Short Polling, and I wanted to try to use Comet, to see what the performance would be. However, if I select Comet, as Polling Type, nothing changes. Still requests each 5 seconds. Does Comet work? Is that based on HTML5's Server Side Events (eventsource)? I think it would save resources. Also, I am not sure if I understand the text on that page. Should the pros and cons for the two types be switched? That the pros and cons of one belong to the other? Greets

After you change to Comet mode, the interval between requests should increase to 30s.

In comet mode, FreiChat maintains a request for 30s and during that time if there is any new message , it replies back to the browser.

May be you reduced the polling time to 5s ?

After you change to Comet mode, the interval between requests should increase to 30s. In comet mode, FreiChat maintains a request for 30s and during that time if there is any new message , it replies back to the browser. May be you reduced the polling time to 5s ?
Necessity is the mother of all inventions!
edited Dec 5 '14 at 6:13 am

The interval is still set on 30 seconds. I changed the setting to 'Comet', saved changes, cleared cache of Firefox, and logged in again on the user site. But still each 5 seconds a request.

I guess it will only become a problem with large number of users. A thousand users means a thousands processes running on the server. (in short polling mode, if I understand it correctly)

And was I right about the pros and cons being switched? Or are they correct the way they are?

The interval is still set on 30 seconds. I changed the setting to 'Comet', saved changes, cleared cache of Firefox, and logged in again on the user site. But still each 5 seconds a request. I guess it will only become a problem with large number of users. A thousand users means a thousands processes running on the server. (in short polling mode, if I understand it correctly) And was I right about the pros and cons being switched? Or are they correct the way they are?

Found the cause. In Freichat Backend, ACL, I disabled 'Chatroom' for both the Guest and the User. As a result, in client/main.php you have the following:

$show_chatroom_plugin = 'disabled';

When a request is made, to server/freichat.php, function getmembers(), $this->show_chatroom_plugin has the value of 'enabled'. As a consequence (when using Comet) the code is confused because it thinks chatroom is enabled, but the message times are different, so each time a request is made, it immediately thinks there is a new message, breaks the loop and returns. So while using Comet, you would expect a long request (for instance 30 sec), but it shows a short request. And the request is short, because the code thinks there is a new message, and returns, but there isn't a new message. So then it seems the polling is wrong, because normally you would think short requests are only done by the Short Polling option.

Solution:

change

$this->show_chatroom_plugin = 'enabled';

into 'disabled', in arg.php. Then the polling works as expected!

Found the cause. In Freichat Backend, ACL, I disabled 'Chatroom' for both the Guest and the User. As a result, in client/main.php you have the following: ```` $show_chatroom_plugin = 'disabled'; ```` When a request is made, to server/freichat.php, function getmembers(), $this->show_chatroom_plugin has the value of 'enabled'. As a consequence (when using Comet) the code is confused because it thinks chatroom is enabled, but the message times are different, so each time a request is made, it immediately thinks there is a new message, breaks the loop and returns. So while using Comet, you would expect a long request (for instance 30 sec), but it shows a short request. And the request is short, because the code thinks there is a new message, and returns, but there isn't a new message. So then it seems the polling is wrong, because normally you would think short requests are only done by the Short Polling option. Solution: change ```` $this->show_chatroom_plugin = 'enabled'; ```` into 'disabled', in arg.php. Then the polling works as expected!

That code sets the initial state of the argument, which is enabled.
What you are saying is that, when the ACL is set to not show the chatrooms, that this field default value isn't changed by a variable linked to the ACL settings.

ie if nothing is set, then the chatroom plug is enabled.
If the ACl is changed so that the chatrooms are disabled, the system needs to replace the default setting with "disabled"?
As per the comment above, this is not happening?

That code sets the initial state of the argument, which is enabled. What you are saying is that, when the ACL is set to not show the chatrooms, that this field default value isn't changed by a variable linked to the ACL settings. ie if nothing is set, then the chatroom plug is enabled. If the ACl is changed so that the chatrooms are disabled, the system needs to replace the default setting with "disabled"? As per the comment above, this is not happening?

Just a word of caution:
If you change that setting, the user list in the mobile version stops working.
Better to let the devs sort this one out as changes have unforseen consequences LOL

Just a word of caution: If you change that setting, the user list in the mobile version stops working. Better to let the devs sort this one out as changes have unforseen consequences LOL

Well the problem is in server/freichat.php, function getmembers():

            $time = time();
            while ((time() - $time) < $this->poll_time) {
                // $new_data = array();    



                $freichat = $this->update_message_data($freichat);
                if ($freichat->time > $_GET['time'] /* || $this->isset_video_offer == true */) {
                    // a new message !
                    $new_data = true;
                }


                if ($this->show_chatroom_plugin == "enabled") {
                    if ($freichat->chatroom_mesg_time > $_GET['chatroom_mesg_time']) {
                        // a new message 
                        $new_data = true;
                    }
                }


                if ($new_data == true) {
                    echo json_encode($freichat);
                    break;
                }

                usleep(($this->chatspeed * 1000));
            }

If Comet is set, it goes into this loop, and immediately $new_data is set to 'true', because show_chatroom_plugin is enabled, and the message times are in a way that it thinks there is a new message (this changes by the way, when you post a message yourself).

Thanks for the reply that this setting is used in a lot of other places, it made me realize that my solution was not the right one. What I will do is comment out the $new_data = true; at the chatroom part (I am not using chatrooms). Because I do want the polling to work as expected.

I guess it would be better to find out how the message times work, and fix that. But since I do not use chatrooms, I'll do this dirty fix.

Well the problem is in server/freichat.php, function getmembers(): ```` $time = time(); while ((time() - $time) &amp;lt; $this-&amp;gt;poll_time) { // $new_data = array(); $freichat = $this-&amp;gt;update_message_data($freichat); if ($freichat-&amp;gt;time &amp;gt; $_GET[&#039;time&#039;] /* || $this-&amp;gt;isset_video_offer == true */) { // a new message ! $new_data = true; } if ($this-&amp;gt;show_chatroom_plugin == &quot;enabled&quot;) { if ($freichat-&amp;gt;chatroom_mesg_time &amp;gt; $_GET[&#039;chatroom_mesg_time&#039;]) { // a new message $new_data = true; } } if ($new_data == true) { echo json_encode($freichat); break; } usleep(($this-&amp;gt;chatspeed * 1000)); } ```` If Comet is set, it goes into this loop, and immediately $new_data is set to &#039;true&#039;, because show_chatroom_plugin is enabled, and the message times are in a way that it thinks there is a new message (this changes by the way, when you post a message yourself). Thanks for the reply that this setting is used in a lot of other places, it made me realize that my solution was not the right one. What I will do is comment out the $new_data = true; at the chatroom part (I am not using chatrooms). Because I do want the polling to work as expected. I guess it would be better to find out how the message times work, and fix that. But since I do not use chatrooms, I&#039;ll do this dirty fix.

Ah yes, about the setting. The default is set to 'enabled', and when I change the ACL so that the chatrooms are disabled, the value of $this->show_chatroom_plugin is still 'enabled', in freichat.php. My guess was, that this should be 'disabled'. As you pointed out, my guess was, that the system needed to replace the default setting with 'disabled'. From your answer I concluded that that was not the case, it shouldn't change it. Is that correct? That it shouldn't change it? For instance because the user list in the mobile version stops working?

Ah yes, about the setting. The default is set to &#039;enabled&#039;, and when I change the ACL so that the chatrooms are disabled, the value of $this-&amp;gt;show_chatroom_plugin is still &#039;enabled&#039;, in freichat.php. My guess was, that this should be &#039;disabled&#039;. As you pointed out, my guess was, that the system needed to replace the default setting with &#039;disabled&#039;. From your answer I concluded that that was not the case, it shouldn&#039;t change it. Is that correct? That it shouldn&#039;t change it? For instance because the user list in the mobile version stops working?

It works fine, comet and short polling work as expected after the modification. The rest of the features also still work as expected.

It works fine, comet and short polling work as expected after the modification. The rest of the features also still work as expected.
641
8
3
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft