General developer forum

Web sockets and Moodle

 
 
Gareth J Barnard
Web sockets and Moodle
Group DevelopersGroup Particularly helpful Moodlers

Hi all,

Just a thought, but I've been reading up about Web sockets and what they do with regards server -> client and vice versa communication and wondered if there were / are / is plans for inclusion as a Moodle core API?

I've had a user request that the AJAX calls I make to update the Collapsed Topics calls be less server demanding as they update every time a toggle is clicked (cannot be currently sorted with the 'onunload' event in JavaScript as not consistently implemented in all browsers).  I'm currently using Tim's easy to use set user preference code.  So, wondered if Web sockets would be more efficient and less server demanding for updates.

Cheers,

Gareth

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Web sockets and Moodle
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

I saw some discussion of that recently, but I can't think where. The potential issue is the way Moodle locks the session, but there is probably a way around that. Still, worth persuing. As you say, it is a generally useful technique, and it should be possible to make it work in Moodle, with some thought.

 
Average of ratings: -
Dan at desk in Moodle HQ, Perth
Re: Web sockets and Moodle
Group DevelopersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers
I've only looked very briefly in the past, but I don't think that websockets are really compatible with the request-based apache-style webserver model which we use currently in Moodle.

They are persistant connections which, to be used effectively, need something non-blocking like node.js for the requests to be served properly.

So, I don't think it can be widely applied to Moodle for some time. It'd be a nice project to convert the old (mostly unmaintained) chat daemon to web-sockets though, that uses that model already.

http://www.html5rocks.com/en/tutorials/websockets/basics/
 
Average of ratings: -
Gareth J Barnard
Re: Web sockets and Moodle
Group DevelopersGroup Particularly helpful Moodlers

Dear Tim and Dan,

Thank you for your response.  I believe that there could be a few PHP web socket libraries out there.  Would be a good project to get as a core API like jQuery and others.  I suppose from an efficiency point of view it all depends on the size and processing time expended on communication with WebSockets against bog standard AJAX over HTTP.

I also see the point Dan of the request based model where you might not know when to terminate a connection when a client leaves.  Food for thought though smile

Cheers,

Gareth

 
Average of ratings: -