Files
moodle/mod/chat/gui_header_js/index.php
T
martinlanghoff 930413b133 mod/chat: Normal method - introducing "Stream" updates.
This is an alternative version of jsupdate.php that acts
as a long-running daemon. It will feed/stall/feed JS updates
to the client. From the module configuration select "Stream"
updates.

The client connection is not forever though. Once we reach
CHAT_MAX_CLIENT_UPDATES (currently 1000), it will force
the client to re-fetch it.

This buys us all the benefits that chatd has, minus the setup,
as we are using apache to do the daemon handling.

Chat still defaults to the normal update method, which is now
optimised to take advantage of keepalives -- so this change is
safe. The instructions in the config page also indicate that this
mode may not be well supported everywhere. It hasn't been
tested on IIS for starters.

In terms of relative cost -- if each hit on jsupdate.php incurs
on ~20 db queries and delivers one update to the client, each hit
on jsupdate takes ~20 queries, and then roughly 2~3 queries to
serve each of the next 1000 updates. On busy sites, the difference
is huge.

There is still room for enhancements in both keepalive and stream
update methods. I am pretty sure we can trim DB queries more.
2006-04-19 02:20:48 +00:00

83 lines
3.1 KiB
PHP

<?php // $Id$
require_once('../../../config.php');
require_once('../lib.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
if (!$chat = get_record('chat', 'id', $id)) {
error('Could not find that chat room!');
}
if (!$course = get_record('course', 'id', $chat->course)) {
error('Could not find the course this belongs to!');
}
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
error('Course Module ID was incorrect');
}
require_login($course->id, false, $cm);
if (isguest()) {
error('Guest does not have access to chat rooms');
}
if (!$cm->visible and !isteacher($course->id)) {
print_header();
notice(get_string("activityiscurrentlyhidden"));
}
/// Check to see if groups are being used here
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
if ($groupid = get_and_set_current_group($course, $groupmode, $groupid)) {
if (!$group = get_record('groups', 'id', $groupid)) {
error("That group (id $groupid) doesn't exist!");
}
$groupname = ': '.$group->name;
} else {
$groupname = ': '.get_string('allparticipants');
}
} else {
$groupid = 0;
$groupname = '';
}
$strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!!
if (!$chat_sid = chat_login_user($chat->id, 'header_js', $groupid, $course)) {
error('Could not log in to chat room!!');
}
$params = "chat_sid=$chat_sid";
// fallback to the old jsupdate, but allow other update modes
$updatemode = 'jsupdate';
if (!empty($CFG->chat_normal_updatemode)) {
$updatemode = $CFG->chat_normal_updatemode;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=<?php echo current_charset(); ?>" />
<title>
<?php echo "$strchat: $course->shortname: ".format_string($chat->name,true)."$groupname" ?>
</title>
</head>
<frameset cols="*,200" border="5" framespacing="no" frameborder="yes" marginwidth="2" marginheight="1">
<frameset rows="0,0,*,50" border="0" framespacing="no" frameborder="no" marginwidth="2" marginheight="1">
<frame src="../empty.php" name="empty" scrolling="no" marginwidth="0" marginheight="0">
<frame src="<?php echo $updatemode ?>.php?<?php echo $params ?>" name="jsupdate" scrolling="no" marginwidth="0" marginheight="0">
<frame src="chatmsg.php?<?php echo $params ?>" name="msg" scrolling="auto" marginwidth="2" marginheight="1">
<frame src="chatinput.php?<?php echo $params ?>" name="input" scrolling="no" marginwidth="2" marginheight="1">
</frameset>
<frame src="users.php?<?php echo $params ?>" name="users" scrolling="auto" marginwidth="5" marginheight="5">
</frameset>
<noframes>
Sorry, this version of Moodle Chat needs a browser that handles frames.
</noframes>
</html>