Page 1 of 1
[SOLVED] Best way to use ?
Posted: Sat Sep 13, 2025 12:52 pm
by CrazyCat
Hello there,
I've some troubles with the irc2sql module of anope, so I decided to use xmlrpc to get live infos about the channels, and I need some advices.
On the channel page, I've several info about the channel, perfect, but also about the users: nick, level, realname, country, away (when the PR will be accepted

) and modes (to check if it's a bot or not). To get these infos, I can:
- use channel->get() with level 5 => could make a really big object
- use channel->get() normaly (level 3) and loop on the members to do a user->get() with level 2 => could do a lot of queries
Which solution could be the best ? Or do you have another one ?
Re: Best way to use ?
Posted: Sat Sep 13, 2025 7:05 pm
by Syzop
I would certainly not do the 2nd method. You could do the 1st, yeah, but then for sure cache the response for like 5 or 10 seconds, so it can be re-used by other people loading that page. If it's PHP, I usually use memcache for that, where you can just throw a key = value in, with "key" being or containing the channel name and the "value" being the server response (the entire JSON string).
Re: Best way to use ?
Posted: Sat Sep 13, 2025 10:49 pm
by CrazyCat
I was thinking about using a cache, but make by myself: a simple text file per channel, and check of the modification date. And probably the cache will contain the html I generate, so I just read and display rather than reparse datas. And 10s seems a good rate
Thanks Syzop
Re: Best way to use ?
Posted: Wed Sep 17, 2025 2:57 pm
by CrazyCat
Here is the way I cache my datas, simple but working:
Code: Select all
function chanCache($chan) {
global $unrealapi;
$file = '/tmp/'.$chan.'.tmp';
if (!is_file($file) || filemtime($file)<(time()-10)) {
$rpc = new UnrealIRCd\Connection("wss://127.0.0.1:8600/", $unrealapi, ['tls_verify' => FALSE]);
$uchannel = $rpc->channel()->get('#'.$chan, 5);
$fo = fopen($file, 'w');
fputs($fo, serialize($uchannel));
fclose($fo);
}
return unserialize(file_get_contents($file));
}
No need to use memcache, fully portable on any configuration
I know use json-RPC for the live datas (
https://zeolia.chat/canaux/ and any channel page), and also for the webmasters tools (
https://zeolia.chat/outils/ , tab "Afficher vos statistiques")
Just waiting for the 6.2.1 to add the AWAY

Re: Best way to use ?
Posted: Fri Sep 26, 2025 5:26 pm
by CrazyCat
Syzop kindly gave me some tips on how to improve and secure my caching function, so here is the result:
Code: Select all
function chanCache($chan) {
global $unrealapi;
$file = '/tmp/'.hash('sha256', $chan).'.src';
if (!is_file($file) || filemtime($file)<(time()-10)) {
$rpc = new UnrealIRCd\Connection("wss://127.0.0.1:8600/", $unrealapi, ['tls_verify' => FALSE]);
$uchannel = $rpc->channel()->get('#'.$chan, 5);
$fo = fopen($file.'.tmp', 'w');
fputs($fo, serialize($uchannel));
fclose($fo);
rename($file.'.tmp', $file);
}
return unserialize(file_get_contents($file));
}
Thanks
