From 03cd8e12c68e3e6c4a9002fe74de6cca551cec18 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Sun, 1 Jun 2014 06:26:29 -0500 Subject: [PATCH] Update optimization guide for 1.9.8 --- documentation/optimization.html | 51 ++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/documentation/optimization.html b/documentation/optimization.html index 39f24b13bc..8621238db3 100755 --- a/documentation/optimization.html +++ b/documentation/optimization.html @@ -40,7 +40,7 @@

Contents

    -
  1. Using xCache, APC or Memcache
  2. +
  3. Using xCache, APC, Memcache or Memcached
  4. Slow queries
  5. Indexes caching
  6. Sessions directories
  7. @@ -173,6 +173,55 @@ If you prefer using APC, you } ... +
    +If you use php5-memcached (different set of functions than php5-memcache!), then this piece of code would look like this (you need to adjust depending on your settings): +
    +    global $_configuration;
    +    $_course    = api_get_course_info();
    +    $course_id  = api_get_course_id();
    +    $user_id    = api_get_user_id();
    +
    +    $html = '';
    +    $xc = method_exists('Memcached', 'add');
    +    if ($xc) {
    +        // Make sure the server is available
    +        $xm = new Memcached;
    +        $xm->addServer('localhost', 11211);
    +        // The following concatenates the name of the database + the id of the
    +        // access url to make it a unique variable prefix for the variables to
    +        // be stored
    +        $xs = $_configuration['main_database'].'_'.$_configuration['access_url'].'_';
    +    }
    +    $number = 0;
    +    if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting('showonline', 'users') == 'true' AND $user_id) OR (api_get_setting('showonline', 'course') == 'true' AND $user_id AND $course_id)) {
    +        if ($xc) {
    +            if ($xm->get($xs.'wio_count_simple')) {
    +                $number = $xm->get($xs.'wio_count_simple');
    +            } else {
    +                $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
    +                $xm->set($xs.'wio_count_simple',$number,120);
    +            }
    +        } else {
    +              $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
    +        }
    +        $number_online_in_course = 0;
    +        if (!empty($_course['id'])) {
    +            if ($xc) {
    +                if ($xm->get($xs.'wio_count_simple_'.$_course['id'])) {
    +                    $number_online_in_course = $xm->get($xs.'wio_count_simple_'.$_course['id']);
    +                } else {
    +                    $number_online_in_course = who_is_online_in_this_course_count($user_id, api_get_setting('time_limit_whosonline'), $_course['id']);
    +                    $xm->set($xs.'wio_count_simple_'.$_course['id'],$number_online_in_course,120);
    +                }
    +            } else {
    +                $number_online_in_course = who_is_online_in_this_course_count(api_get_user_id(), api_get_setting('time_limit_whosonline'), $_course['id']);
    +            }
    +        }
    +        // ...
    +
    + + +

    It is also worth noting that the Université de Genève, Switzerland, observed that the calculation of the total size used by course documents is one of the heaviest queries in Chamilo, so you might want to cache the results of this one as well, using the same technique.

    Finally, if your portal is highly public *and* you are showing the popular courses on the homepage, you might want to also reduce the amount of queries this generates, using the same technique as above, but for the main/inc/lib/auth.lib.php library, looking for the "Tracking::get_course_connections_count()" call: