[SOLVED] Best way to use ?

Questions/suggestions/support regarding the admin panel, the JSON-RPC interface and other such software

Moderator: Supporters

Post Reply
CrazyCat
Posts: 272
Joined: Thu Apr 28, 2005 1:05 pm
Location: France
Contact:

[SOLVED] Best way to use ?

Post 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 ?
Syzop
UnrealIRCd head coder
Posts: 2181
Joined: Sat Mar 06, 2004 8:57 pm
Location: .nl
Contact:

Re: Best way to use ?

Post 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).
CrazyCat
Posts: 272
Joined: Thu Apr 28, 2005 1:05 pm
Location: France
Contact:

Re: Best way to use ?

Post 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
CrazyCat
Posts: 272
Joined: Thu Apr 28, 2005 1:05 pm
Location: France
Contact:

Re: Best way to use ?

Post 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 :)
CrazyCat
Posts: 272
Joined: Thu Apr 28, 2005 1:05 pm
Location: France
Contact:

Re: Best way to use ?

Post 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 :)
Post Reply