optimization.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <html lang="en">
  2. <head>
  3. <meta charset="utf-8" />
  4. <title>Chamilo Optimization Guide</title>
  5. <link rel="stylesheet" href="../public/build/css/app.css" type="text/css" media="screen,projection" />
  6. <link rel="stylesheet" href="../public/build/css/themes/chamilo/default.css" type="text/css" media="screen,projection" />
  7. <link rel="stylesheet" href="default.css" type="text/css" media="screen,projection" />
  8. <link rel="stylesheet" href="../public/build/css/print.css" type="text/css" media="print" />
  9. <script src="../public/build/app.js"></script>
  10. </head>
  11. <body>
  12. <nav class="navbar navbar-default navbar-fixed-top">
  13. <div class="container">
  14. <div class="navbar-header">
  15. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
  16. <span class="sr-only">Toggle navigation</span>
  17. <span class="icon-bar"></span>
  18. <span class="icon-bar"></span>
  19. <span class="icon-bar"></span>
  20. </button>
  21. <a class="navbar-brand" href="#">Chamilo - Documentation</a>
  22. </div>
  23. <div class="collapse navbar-collapse">
  24. <ul class="nav navbar-nav">
  25. <li><a href="index.html">Home</a></li>
  26. <li class="active"><a href="readme.html">About</a></li>
  27. <li><a href="license.html">License</a></li>
  28. <li><a href="credits.html">Credits</a></li>
  29. <li ><a href="dependencies.html">Dependencies</a></li>
  30. <li><a href="changelog.html">Changelog</a></li>
  31. </ul>
  32. </div><!--/.nav-collapse -->
  33. </div>
  34. </nav>
  35. <div class="container">
  36. <h1>Chamilo : Optimization Guide</h1>
  37. <a href="index.html">Documentation</a> &gt; Optimization Guide
  38. <p>In seldom cases, you will need to start looking into efficiency issues
  39. with Chamilo. This guide is a work in progress intended to help
  40. administrators optimize their Chamilo installation.</p>
  41. <h2><b>Contents</b></h2>
  42. <ol>
  43. <li><a href="#1.Using-XCache">Using opcaches</a></li>
  44. <li><a href="#2.Slow-queries">Slow queries</a></li>
  45. <li><a href="#3.Indexes-caching">Indexes caching</a></li>
  46. <li><a href="#4.Sessions-directories">Sessions directories</a></li>
  47. <li><a href="#5.Users-upload-directories">Users upload directories</a></li>
  48. <li><a href="#6.Zlib-compression">Zlib compressed output</a></li>
  49. <li><a href="#7.High-numbers-memory">Memory considerations for high numbers of users</a></li>
  50. <li><a href="#8.Avoid-non-fixed-values">Avoiding non-fixed values</a></li>
  51. <li><a href="#9.xsendfile">Speeding file downloads with mod_xsendfile</a></li>
  52. <li><a href="#10.igbinary">IGBinary for faster courses backups and better sessions</a></li>
  53. <li><a href="#11.permissions-check">Removing files download permissions check</a></li>
  54. <li><a href="#12.MySQL-compression">MySQL/MariaDB compression</a></li>
  55. <li><a href="#13.increasing-php-limits">Increasing PHP limits</a></li>
  56. </ol>
  57. <h2><a name="1.Using-XCache"></a>1. Using opcaches</h2>
  58. <h3>Zend OpCode (Zend Optimizer+)</h3>
  59. From version 5.5, PHP includes the Zend OpCache Optimizer, which can
  60. bring considerable efficiency improvements and is very reliable.
  61. Using OpCache should come by default, but if you want to make sure it's
  62. running, just check that your opcache.ini config file says
  63. <pre>opcache.enable = 1</pre>
  64. Some websites will recommend the addition of additional settings, and this
  65. is really up to you. Check
  66. <a href="http://php.net/manual/en/opcache.configuration.php">the official OpCache config page for more information</a>.
  67. To check if OpCache is effectively running, you can check the
  68. <a href="/main/admin/system_status.php?section=php">Chamilo systems status page</a>
  69. on the administration page, or you can check it in phpinfo, if you have any script with it.
  70. Zend OpCache is an "opcode" cache, meaning it will compile static code to make their processing faster.
  71. However, this will not allow you to "store" shared variables in memory between all users. To do that, we suggest
  72. you complement Zend OpCache (opcode) with a user-land cache like APCu.
  73. <h3>APCu</h3>
  74. You can also check whether APCu is working or not from the systems status page. Check
  75. <a href="http://php.net/manual/en/apcu.configuration.php">the official APCu config page</a>
  76. for configuration options.
  77. In previous versions, this optimization guide contained information about how to use xCache, APC or Memcache to
  78. boost the number of online users. However, starting from version 1.11, code has been added to Chamilo to use
  79. APCu by default from the banner.lib.php library, so as long as APCu is installed and running, you'll benefit from
  80. this optimization naturally.
  81. <h3>Other items</h3>
  82. <p>It is also worth noting that the Université de Genève, Switzerland, observed
  83. that the calculation of the total size used by course documents is one of
  84. the heaviest queries in Chamilo, so you might want to cache the results of
  85. this one as well, using the same technique.</p>
  86. <p>Finally, if your portal is highly public *and* you are showing the popular
  87. courses on the homepage, you might want to also reduce the amount of
  88. queries this generates, using the same technique as above, but for the
  89. main/inc/lib/auth.lib.php library, looking for the
  90. "Tracking::get_course_connections_count()" call:</p>
  91. <pre>
  92. while ($row = Database::fetch_array($result)) {
  93. $row['registration_code'] = !empty($row['registration_code']);
  94. $count_users = CourseManager::get_users_count_in_course($row['code']);
  95. $xc = function_exists('apc_exists');
  96. if ($xc) {
  97. $apc = apc_cache_info(null, true);
  98. $apx_end = $apc['start_time']+$apx['ttl'];
  99. if (apc_exists('my_campus_course_visits_'.$row['code']) AND (time() < $apc_end) AND apc_fetch('my_campus_course_visits_'.$row['code']) > 0) {
  100. $count_connections_last_month = apc_fetch('my_campus_course_visits_'.$row['code']);
  101. } else {
  102. $count_connections_last_month = Tracking::get_course_connections_count($row['code'], 0, api_get_utc_datetime(time() - (30 * 86400)));
  103. apc_store('my_campus_course_visits_'.$row['code'], $count_connections_last_month, $apc['ttl']);
  104. }
  105. } else {
  106. $count_connections_last_month = Tracking::get_course_connections_count($row['code'], 0, api_get_utc_datetime(time() - (30 * 86400)));
  107. }
  108. ...
  109. }
  110. </pre>
  111. Finally, the Free Campus of Chamilo has a very specific case of slow query:
  112. the courses catalog! Because there might be more than 32,000 courses in
  113. there, getting the number of "Connections last month" can be a disastrous
  114. query in terms of performances. This is why you should try to cache the
  115. results as well.<br />
  116. Obviously, as we are speaking about showing the number of visits this month,
  117. it doesn't really matter if the number doesn't refresh for an hour or so...<br />
  118. Locate the main/inc/lib/course_category.lib.php file, open it and go to the
  119. browseCoursesInCategory() function.<br />
  120. Locate the $count_connections_last_month = Tracking::get_course_connections_count(...)
  121. call, and wrap in into something like this (you'll have to update this to use APCu):
  122. <pre>
  123. $xc = method_exists('Memcached', 'add');
  124. if ($xc) {
  125. // Make sure the server is available
  126. $xm = new Memcached;
  127. $xm->addServer('localhost', 11211);
  128. // The following concatenates the name of the database + the id of the
  129. // access url to make it a unique variable prefix for the variables to
  130. // be stored
  131. $xs = $_configuration['main_database'].'_'.$_configuration['access_url'].'_';
  132. }
  133. $result = Database::query($sql);
  134. $courses = array();
  135. while ($row = Database::fetch_array($result)) {
  136. $row['registration_code'] = !empty($row['registration_code']);
  137. $count_users = CourseManager::get_users_count_in_course($row['code']);
  138. if ($xc) {
  139. if ($xm->get($xs.'cccount_'.$row['code'])) {
  140. $number = $xm->get($xs.'cccount_'.$row['code']);
  141. } else {
  142. $count_connections_last_month = Tracking::get_course_connections_count($row['code'], 0, api_get_utc_datetime(time() - (30 * 86400)));
  143. $xm->set($xs.'cccount_'.$row['code'], $count_connections_last_month, 3600);
  144. }
  145. } else {
  146. $count_connections_last_month = Tracking::get_course_connections_count($row['code'], 0, api_get_utc_datetime(time() - (30 * 86400)));
  147. }
  148. ...
  149. </pre>
  150. <hr />
  151. <h2><a name="2.Slow-queries"></a>2. Slow queries</h2>
  152. Enable slow_queries in /etc/mysqld/my.cnf, restart MySQL then follow using sudo tail -f /var/log/mysql/mysql-slow.log
  153. <br /><br />
  154. In Chamilo 1.9 in particular, due to the merge of all databases into one, you might experience performance issues.<br />
  155. To solve this performance issue, you can execute the following query manually in your database:<br />
  156. <pre>
  157. ALTER TABLE user_rel_tag ADD INDEX idx_user_rel_tag_user (user_id);
  158. </pre>
  159. <br /><br />
  160. In Chamilo 1.10.0 (the first version of the serie), many indexes were forgotten, so you can boost your database by adding the following indexes:<br />
  161. <pre>
  162. alter table extra_field_values add index idx_extra_field_values (field_id, item_id);
  163. alter table usergroup_rel_user add index idx_usergroup_ru (usergroup_id);
  164. alter table usergroup_rel_user add index idx_usergroup_ru_u (user_id);
  165. alter table c_student_publication add index idxstudpub_cid (c_id);
  166. alter table c_student_publication add index idxstudpub_uid (user_id);
  167. alter table c_quiz_question add index idx_cqq_cid (c_id);
  168. alter table c_quiz_rel_question ADD INDEX idx_cqrq_qid (question_id);
  169. alter table c_quiz_rel_question ADD INDEX idx_cqrq_cid (c_id);
  170. alter table c_quiz_answer add index idx_qa_cidqid (c_id, question_id);
  171. </pre>
  172. In Chamilo 1.10.6, two additional queries were confirmed to still have effect a considerable effect:
  173. <pre>
  174. ALTER TABLE c_quiz_question_rel_category ADD INDEX idx_qqrc_qid (question_id);
  175. ALTER TABLE c_lp_item_view ADD INDEX idx_clpiv_c_i_v (c_id, id, view_count);
  176. </pre>
  177. Note that, because these situations only occur when a portal is under real-world high-load stress, we only get to
  178. find out about these possible bottlenecks after we release stable versions of Chamilo. This is why we list those
  179. queries here. However, as soon as we confirm them with a few real life scenarios, we add them into the core of
  180. Chamilo so you can benefit from them immediately by installing a new version.
  181. <p>In Chamilo 1.11.x you can boost the DB tables related surveys invitations by adding the following indexes:</p>
  182. <pre>
  183. CREATE INDEX idx_survey_q_qid ON c_survey_question (question_id);
  184. CREATE INDEX idx_survey_code ON c_survey (code);
  185. CREATE INDEX idx_survey_inv_code ON c_survey_invitation (survey_code);
  186. CREATE INDEX idx_survey_qo_qid ON c_survey_question_option (question_id);
  187. </pre>
  188. Also by adding a index on access_url_rel_session to improve the course/session list
  189. <pre>
  190. CREATE INDEX idx_accessurs_sid ON access_url_rel_session (session_id);
  191. </pre>
  192. And finally, if you have lots of gradebook stuff, add this
  193. <pre>
  194. ALTER TABLE gradebook_result ADD INDEX idx_gb_uid_eid (user_id, evaluation_id);
  195. </pre>
  196. <hr />
  197. <h2><a name="3.Indexes-caching"></a>3. Indexes caching</h2>
  198. One good reference: <a href="http://dev.mysql.com/doc/refman/5.6/en/multiple-key-caches.html">MySQL documentation on multiple key caches</a><br />
  199. <hr />
  200. <h2><a name="4.Sessions-directories"></a>4. Sessions directories</h2>
  201. <p>On large implementations, the users sessions might be stored in numbers too large (hundreds of thousands) to be
  202. efficiently managed by the filesystem is stored in one single folder. In order to avoid that, you can either store
  203. your sessions in another key-value storage (memcache, redis, etc) or you can instruct PHP to store your session
  204. files in a directory with a certain level of subdirectories (so sessions are spread across multiple directories
  205. instead of inside just one.</p>
  206. <p>This is done by adding the following setting to your php.ini or your Apache's Virtual Host</p>
  207. <pre>php_admin_value session.save_path 1;/var/www/test.chamilo.org/sessions/</pre>
  208. <p>Please note that, by defining a different directory than your system's default, you will need to reconfigure
  209. your system's session cleaning procedure, which is usually defined under /etc/cron.d/php, so that it cleans
  210. this specific directory as well.</p>
  211. <hr />
  212. <h2><a name="5.Users-upload-directories"></a>5. Users upload directories</h2>
  213. The default in Chamilo is now to spread user accounts in 10 different directories inside app/upload/users/ to avoid
  214. overloading that specific directory. Nothing to be done here. Please move on.
  215. <hr />
  216. <h2><a name="6.Zlib-compression"></a>6. Zlib compressed output</h2>
  217. Although this will not make your server faster, compressing the pages you are sending to the users will definitely
  218. make them feel like your website's responses are a lot faster, and thus increase their well-being when using Chamilo.<br /><br />
  219. Zlib output compression has to be set at two levels: PHP configuration for PHP pages and Apache for images and CSS.<br /><br />
  220. To update the PHP configuration (either in php.ini or in your VirtualHost), use the
  221. <a href="http://php.net/manual/en/zlib.configuration.php">zlib.output_compression</a>. If you set this inside your
  222. Apache's VirtualHost, you should use the following syntax.
  223. <pre>
  224. php_value zlib.output_compression 1
  225. </pre>
  226. <br />
  227. Configuring your Apache server to use output compression is a bit trickier. You have to use <a href="http://httpd.apache.org/docs/2.2/mod/mod_deflate.html">the mod_deflate module</a> to do it. Your configuration should look like something like this (please read the corresponding documentation before implementing in production).<br />
  228. Easy mode:
  229. <pre>
  230. AddOutputFilterByType DEFLATE text/html text/plain text/xml
  231. </pre> or, for every content type (dangerous) you can put the following inside a location or directory block:<pre>SetOutputFilter DEFLATE</pre>
  232. <br />
  233. Advanced mode:
  234. <pre>
  235. <Location />
  236. # Insert filter
  237. SetOutputFilter DEFLATE
  238. # Netscape 4.x has some problems...
  239. BrowserMatch ^Mozilla/4 gzip-only-text/html
  240. # Netscape 4.06-4.08 have some more problems
  241. BrowserMatch ^Mozilla/4\.0[678] no-gzip
  242. # MSIE masquerades as Netscape, but it is fine
  243. # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  244. # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
  245. # the above regex won't work. You can use the following
  246. # workaround to get the desired effect:
  247. BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
  248. # Don't compress images
  249. SetEnvIfNoCase Request_URI \
  250. \.(?:gif|jpe?g|png)$ no-gzip dont-vary
  251. # Make sure proxies don't deliver the wrong content
  252. Header append Vary User-Agent env=!dont-vary
  253. </Location>
  254. </pre>
  255. <hr />
  256. Don't have time or resources to optimize your Chamilo installation yourself? Hire an <a href="http://www.chamilo.org/en/providers">official Chamilo provider</a> and get it sorted out professionally by specialists.
  257. <a href="http://validator.w3.org/check?uri=referer"><img src="//www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" style="margin: 1em; float: right;" height="31" width="88" /></a>
  258. <a href="http://jigsaw.w3.org/css-validator/">
  259. <img src="//jigsaw.w3.org/css-validator/images/vcss-blue" style="margin: 1em; float: right;" alt="Valid CSS" />
  260. </a>
  261. <hr />
  262. <h2><a name="7.High-numbers-memory"></a>Memory considerations for high numbers of users</h2>
  263. Some administration scripts *have to* handle lists of all users, and this might have a considerable impact on portals with very high numbers of users. For example, the main/admin/add_users_to_session.php script that handles the registration of users into a specific session, if used with the (non-default) full list of users, will devour about 3KB per user, which, for 100,000 users, translates into the need for around 300MB of RAM just to show this page, and to around 3GB for 1,000,000 users.<br />
  264. This mode is not loaded by default, but could still be selected, leading to a "Fatal error: Allowed memory size ... exhausted" message.<br />
  265. The only non-scripted solution here is to allow for the corresponding amount of RAM for your PHP configuration (<em>memory_limit = 300M</em>) or your specific VirtualHost if you use mod-php5 (<em>php_value memory_limit 300M</em>).<br/>
  266. <hr />
  267. <h2><a name="8.Avoid-non-fixed-values"></a>Avoiding dynamic values</h2>
  268. Many things in Chamilo are written focusing on the ease of use, even for the
  269. administrator. Sometimes, these settings are weighing a little bit more on
  270. the system. This is the case, between others, of the mail.conf.php file
  271. (being loaded unconditionally) and its CONSTANT "IS_WINDOWS_OS", which is
  272. defined by a function call (api_is_windows_os()) at the beginning of
  273. main_api.lib.php.
  274. The definition of this constant (which is executed at *every* page load) can
  275. easily be avoided, and the only place where it is used unconditionally
  276. (mail.conf.php) can be modified to set the line as you expect it
  277. (depending on whether you use sendmail/exim or smtp).
  278. <pre>
  279. $platform_email['SMTP_MAILER'] = 'smtp';
  280. </pre>
  281. or
  282. <pre>
  283. $platform_email['SMTP_MAILER'] = 'mail';
  284. </pre>
  285. In fact, the complete loading of mail.conf.php can also be avoided if
  286. loaded conditionally (with <i>require_once</i>) when sending an
  287. e-mail (which is the only case where it is useful).
  288. <p>
  289. As an additional node, on very active portals with a lot of courses
  290. for each users, the icons that appear next to the courses illustrating
  291. changes in the corresponding course might be heavyweighted. You can
  292. alter slightly the behaviour by not querying for notifications you
  293. don't care about, like dropbox, notebook or chat. Change this in
  294. main/inc/lib/display.lib.php, in function show_notification().
  295. </p>
  296. <hr />
  297. <h2><a name="9.xsendfile"></a>Speeding file downloads with mod_xsendfile</h2>
  298. <p>It might have come to your attention that file downloads through Chamilo
  299. might get slow, under default conditions, in particular using Apache 2.</p>
  300. <p>There are several ways to fix this, one of which is removing the .htaccess
  301. inside the courses/ directory. This, however, will remove all permissions
  302. checks on the files contained in this directory, so... most of the time,
  303. not ideal unless your portal is *really* open to the world.</p>
  304. <p>Another technique, revealed to us by
  305. <a href="http://stackoverflow.com/users/46594/virtualblackfox">VirtualBlackFox</a>
  306. on <a href="http://stackoverflow.com/questions/3697748/fastest-way-to-serve-a-file-using-php">this Stackoverflow post</a>,
  307. is to use the X-SendFile module for Apache 2.2+ (other web servers might
  308. offer other solutions, or avoid the problem initially).</p>
  309. <p>Installing the X-SendFile module will depend on your operating system,
  310. but if you use Ubuntu, you'll have to check you are including the "universe"
  311. repository inside your packages sources (check /etc/apt/sources.list), then:
  312. <pre>
  313. sudo apt-get update
  314. sudo apt-get install libapache2-mod-xsendfile
  315. sudo service apache2 restart
  316. </pre>
  317. Once you're done with installing, you'll have to configure Chamilo to use it.<br />
  318. First, edit your VirtualHost or your Apache configuration in general (in Ubuntu,
  319. check the /etc/apache2/ or /etc/apache2/sites-available/ folder). This is done
  320. by adding the following line inside your configuration, and reloading Apache
  321. (example provided on the basis of a virtual host located in
  322. /etc/apache2/sites-available/my.chamilo.net.conf) :
  323. <pre>
  324. sudo vim /etc/apache2/sites-available/my.chamilo.net.conf
  325. # add the following line:
  326. X-SendFile on
  327. # exit the file
  328. sudo service apache2 reload
  329. </pre>
  330. Finally, you'll have to got to your Chamilo configuration file, and add the
  331. following line at the very bottom of the file main/inc/conf/configuration.php:
  332. <pre>
  333. $_configuration['enable_x_sendfile_headers'] = true;
  334. </pre>
  335. Done! Now your downloads should go substantially faster. This is still a
  336. feature in observation. We're not sure the benefits are sufficient, so
  337. don't hesitate to let us know in
  338. <a href="https://support.chamilo.org/issues/6853">the related issue in Chamilo's tracking system</a>
  339. </p>
  340. <hr />
  341. <h2><a name="10.igbinary"></a>IGBinary for courses backups and better
  342. sessions management</h2>
  343. <p>
  344. <a href="http://pecl.php.net/package/igbinary">IGBinary</a> is a small PECL
  345. library that replaces the PHP serializer. It uses less space (so less
  346. memory for serialized objects) and is particularly efficient with memory-based
  347. storages (like Memcached). Use it for course backups
  348. (see <a href="https://support.chamilo.org/issues/4443">issue 4443</a>) or
  349. <a href="http://www.neanderthal-technology.com/2011/11/ubuntu-10-install-php-memcached-with-igbinary-support/">to boost sessions management</a>.
  350. </p>
  351. <hr />
  352. <h2><a name="11.permissions-check"></a>Removing files download permissions check</h2>
  353. <p>
  354. This measure is not cumulative with mod_xsendfile explained above. It is not *recommended*
  355. either, as it removes an important security layer.<br />
  356. <br />
  357. In Chamilo, for security and tracking purposes, all downloaded files pass through PHP
  358. scripts that check whether the user has access to the file given his/her current
  359. permissions. This process requires important database accesses and processing, which
  360. might terminally affect your server's performance. In particular, this can
  361. have a huge effect if having hundreds of simultaneous users accessing
  362. learning paths pages composed of local resources.<br /><br />
  363. The logic behind this verification is that, whatever resources that needs to be
  364. downloaded/viewed that come from the /courses/ directory, the /courses/.htaccess
  365. file with get in the middle and redirect these accesses to a PHP script
  366. (usually called download.php but there are more than one depending on the
  367. type of resource).<br /><br />
  368. If you want to speed up files accesses and you don't really care about whom can
  369. see your files, then an option is to simply change this redirection to
  370. download.php and let Apache treat the file directly.<br /><br />
  371. Furthermore, using a PHP script for the download (unless you have special rules)
  372. will usually prevent static content caching, which will multiply downloads
  373. and use large amount of additional bandwidth.<br /><br />
  374. Typically, the .htaccess will look like this (with additional comments):<br />
  375. <pre>
  376. <IfModule mod_rewrite.c>
  377. RewriteEngine On
  378. RewriteBase /courses/
  379. RewriteCond %{REQUEST_URI} !^/main/
  380. RewriteRule ([^/]+)/document/(.*)&(.*)$ $1/document/$2///$3 [N]
  381. RewriteRule ([^/]+)/scorm/(.*)$ /main/document/download_scorm.php?doc_url=/$2&cDir=$1 [QSA,L]
  382. RewriteRule ([^/]+)/document/(.*)$ /main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L]
  383. RewriteRule ([^/]+)/work/(.*)$ /main/work/download.php?file=work/$2&cDir=$1 [QSA,L]
  384. </IfModule>
  385. </pre><br />
  386. The idea is to allow direct access (without access validation) to resources in the "scorm" directory with:
  387. <pre>
  388. <IfModule mod_rewrite.c>
  389. RewriteEngine On
  390. RewriteBase /courses/
  391. RewriteCond %{REQUEST_URI} !^/main/
  392. RewriteRule ([^/]+)/document/(.*)&(.*)$ $1/document/$2///$3 [N]
  393. RewriteRule ([^/]+)/scorm/(.*)$ /app/courses/$1/scorm/$2 [QSA,L]
  394. RewriteRule ([^/]+)/document/(.*)$ /main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L]
  395. RewriteRule ([^/]+)/work/(.*)$ /main/work/download.php?file=work/$2&cDir=$1 [QSA,L]
  396. </IfModule>
  397. </pre><br />
  398. This is easy, doesn't require a server reload and you should see the results pretty
  399. quickly. As mentioned above, if security of your content is an issue, though,
  400. you should avoid using this technique.
  401. </p>
  402. <p>
  403. You can also mitigate the risk by disabling permissions check only
  404. for some static resource like css,js and fonts files.
  405. <br/>
  406. For that is required to load header module
  407. in apache (check with a2enmod in your favorite root terminal)<br />
  408. add theses line after RewriteBase /courses/:
  409. <pre>
  410. &lt;IfModule mod_headers.c&gt;
  411. # all file name ended with these extensions names will bypass the permission check (and also served by the browser cache at the next request)
  412. &lt;FilesMatch &quot;\.(gif|jpg|jpeg|png|js|pdf|ico|icon|css|swf|avi|mp3|ogg|wav|ttf|otf|eot|woff)$&quot;&gt;
  413. Header unset Cache-Control
  414. Header set Cache-Control &quot;public, max-age=29030400&quot;
  415. RequestHeader unset Cookie
  416. Header unset ETag
  417. &lt;/FilesMatch&gt;
  418. &lt;/IfModule&gt;
  419. # also adjust files here
  420. RewriteRule (\.(html|gif|jpg|jpeg|png|js|pdf|ico|icon|css|swf|avi|mp3|ogg|wav|ttf|otf|eot|woff))$ - [L]
  421. </pre>
  422. </p>
  423. <hr />
  424. <h2><a name="12.MySQL-compression"></a>MySQL/MariaDB compression</h2>
  425. <p>
  426. If your database server is separate from your web server, you have to play with
  427. bandwidth, firewalls, and network restrictions in general.<br />
  428. In particular, when dealing with large-scale portals, the time a SQL query
  429. will take to return to the web server will take longer and, eventually,
  430. in the most critical cases, will take <b>too long</b>, and your web servers
  431. will be completely overloaded (load average very high because the system
  432. is waiting for I/O operations, but processors usage not being very high
  433. is a clear sign of this).<br />
  434. To solve this kind of issues, MySQL and MariaDB offer a data compression
  435. mechanism, which will reduce the amount of data passed between PHP and
  436. the database server. Ultimately, this reduction will lower bandwidth
  437. usage and reduce the impact of numerous and heavy data requests (and
  438. save you).<br />
  439. In 1.10.0, we have added the possibility to enable this compression very
  440. easily, from the configuration.php file, uncommenting the following line:
  441. <pre>
  442. //$_configuration['db_client_flags'] = MYSQL_CLIENT_COMPRESS;
  443. </pre>
  444. This should have an immediate effect on the load average on your server.
  445. </p>
  446. <hr />
  447. <h2><a name="13.increasing-php-limits"></a>Increasing PHP limits</h2>
  448. <p>
  449. As your use of Chamilo increases and you get above the thousands of users,
  450. you're likely to hit a few milestones set by PHP to avoid hacks.
  451. One of them is PHP5.4's Suhosin extension limit post_max_vars, which was
  452. extended into PHP5.5 and above through the max_input_vars limit. This limit
  453. is usually set to 1000. What does it mean?<br />
  454. It means that, when you manipulate any list greater than 1000 items, PHP will
  455. automatically remove anything sent above the first 1000 registers (usually
  456. a little bit less because it needs to add the other input fields of the page).
  457. For example, if subscribing 5 new users to a course where you already have
  458. 1000 users subscribed, you will remain at 1000, although the 1000 will not
  459. necessarily be the 1000 that were there in the first place (they are sent
  460. in order of the elements inside the form, so probably alphabetically,
  461. depending on the page).<br /><br />
  462. Increasing this limit to a higher level (say 10,000 instead of 1000) should
  463. be relatively safe, considering your application is normally not open to
  464. the public (and so also open to the evil kind of users). So, in your
  465. php.ini, this limit should now look like this:<br />
  466. <pre>
  467. max_input_vars = 10000
  468. </pre><br /><br />
  469. A number of other limits might also become an issue in the long run, like
  470. memory_limit, post_max_size, etc. We have given reasonnable recommendations
  471. in the installation process for these values, but remember that if you
  472. have a larger portal than anyone else, you probably need to give it more
  473. care than anyone else.
  474. </p>
  475. <hr />
  476. <h2>Authors</h2>
  477. <ul>
  478. <li>Document redacted and maintained by Yannick Warnier, Zend Certified PHP Engineer, BeezNest Belgium SPRL, <a href="mailto:yannick.warnier@beeznest.com">yannick.warnier@beeznest.com</a>.</li>
  479. </ul>
  480. <hr />
  481. Don't have time or resources to optimize your Chamilo installation
  482. yourself? Hire an <a href="//www.chamilo.org/en/providers">official Chamilo provider</a> and get it sorted out professionally by specialists.<br />
  483. <a href="http://validator.w3.org/check?uri=referer"><img src="//www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" style="margin: 1em; float: right;" height="31" width="88" /></a>
  484. <a href="http://jigsaw.w3.org/css-validator/">
  485. <img src="//jigsaw.w3.org/css-validator/images/vcss-blue" style="margin: 1em; float: right;" alt="Valid CSS" />
  486. </a>
  487. </div>
  488. </body>
  489. </html>