Improve Moodle Performance


Hardware Configuration:

  • The fastest and most effective change to improve performance is to increase the amount of RAM on the web server - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.
  • Better performance is gained by obtaining the best processor capability, i.e. dual or dual core processors.
  • We should use SCSI hard disks instead of SATA drives. SATA drives will increase the system’s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when we have multiple drives. If we already have SATA drives, check that the motherboard and the drives themselves support NCQ (Native Command Queuing).
  • Purchase hard disks with a low seek time. This will improve the overall speed of the system, especially when accessing Moodle’s reports.
  • Size the swap file correctly. The general advice is to set it to 4 x physical RAM.
  • Use a RAID disk system. Although there are many different RAID configurations we can create, the following generally works best:
    • Install a hardware RAID controller (if we can)
    • The operating system and swap drive on one set of disks configured as RAID-1.
    • Moodle, Web server and Database server on another set of disks configured as RAID-5.
  • We should use Gigabit Ethernet for improved latency and throughput. This is especially important when we have the webserver and database server separated out on different hosts.
  • Check the settings on the network card. We can get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.

PHP Performance:

  • It is strongly recommended to use a PHP accelerator to ease CPU load, such as APCPHPAXcacheWinCache or eAccelerator.
  • Increasing the database connection lifetime, could be around session.gc_maxlifetime “14400″

Apache Performance:

  • Set the MaxClients directive correctly. Use this formula to help (which uses 80% of available memory to leave room for spare):

MaxClients = Total available memory * 80% / Max memory usage of apache process

  • Use the latest version of Apache - Apache 2 has an improved memory model which reduces memory usage further.
  • For Unix/Linux systems, consider lowering MaxRequestsPerChild in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits).

MySQL Performance:

  • Enable the query cache with query_cache_type = 1
  • Set query_cache_size = 36M & query_cache_min_res_unit = 2K
  • Set the maximum number of connections may be around 200
  • Optimize database tables weekly and after upgrading Moodle. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of the academic session. This will ensure that index files are up to date. We should Backup our database first and then use:
  • mysql>CHECK TABLE mdl_tablename;
  • mysql>OPTIMIZE TABLE mdl_tablename

The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions. Any errors need to be corrected using REPAIR TABLE.

Thanks to moodle.org

Cheers..

Moodle Error: List of all users shows a fatal error message {Fatal error: Call to undefined method MoodleQuickForm_hidden::MoodleQuickForm_hidden() in …


Hi,

If you every face this error List of all users shows a fatal error message {Fatal error: Call to undefined method MoodleQuickForm_hidden::MoodleQuickForm_hidden() in .. while browsing users in your Moodle installation. The possible reason could be the PHP version issue.

The easiest way to resolve is add in HTML_QuickForm_element (moodle/lib/pear/HTML/QuickForm/element.php)

public function __call($name, $args) {
    $name = str_replace('MoodleQuickForm_', '', $name);

    if ($name == 'passwordunmask') {
        $name = 'password';
    }

    return call_user_func_array(array($this, 'HTML_QuickForm_'.$name), $args);
}

Cheers,
Jaswant

Moodle – auto Dock Side Blocks


There is a small tweak in the code, open  blocks/moodleblock.class.php

function:  html_attributes

line no.: 407

change the 0 to 1:

if ($this->instance_can_be_docked() && get_user_preferences(‘docked_block_instance_’.$this->instance->id, 01)) {

This will dock all Moodle side blocks (not for admin user). If you want to skip any block from being docked just add the block name in the AND condition. For example LOGIN block should not be docked, in that case the code will be

if ($this->instance_can_be_docked() && get_user_preferences(‘docked_block_instance_’.$this->instance->id, 1) && $this->name() != ‘login’) {

Hope it will help you!

How to speed-up your webpage


Last weekend I was working on a mobile web application, the site taking time to load on mobile browser, so I was looking for a solution to improve the webpage speed.

How we can increase  the speed of a web application

1. Compression: There is compression techique, Gzip compression.  Gzip compression can reduce the html, css, javascript file size upto 70%.  And one good news is nowdays most modren browsers support the Gzip compression.

The compression is very simple, you just have to edit the .htaccess file. Add the following code to your .htaccess file


# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

Now everytime when the web page will be refressed, browser will receive the compressed file and it will surely improve the application’s speed.

2. Caching: If we can leverage the browser cache, it can improve the speed, as most of the files are just static, like images, CSS, PDF’s, JS, Docs etc. We can cache those files on user’s browser. Once these files are cached, instead of a new request to server, browser will just fetch the file from local cache.

Again to implement this there is a very simple solution, just edit the .htaccess file and add this code

<IfModule mod_expires.c>

ExpiresActive On

ExpiresByType image/jpg "access 1 year"

ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>

Hope this will help most of you. The latest firefox addon can actually show you whether your page is compressed or not.

Thanks

PHP Validations


Email Validation:

if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo “E-mail is not valid”;
}

 

Integer Validation:

is_int($var)  or is_integer($var)

Returns true/false

Valid: 2, 4, 10

Invalid: “2″, 2.5

 

Float Validation:

is_float($var)

Returns true/false

Valid: 11.5, 1e4

Invalid: “2.5″, 4, 0

 

Numeric Validation:

is_numeric($var)

Returns true/false

Valid: 40, 1e4, 1550, 9.5

Invalid: “2.5″

 

String Validation:

is_string($var)

Returns true/false

Valid: ‘abc’, “abc”

Invalid: 11.5, 23, true

Joomla Extension Manager warning (PHP temporary directory is not set)


Have you ever seen this warning message in your Joomla Extension Manager

The PHP temporary directory is not set. The PHP temporary directory is the directory that PHP uses to store an uploaded file before Joomla! can access this file. Whilst the directory not being set isn’t always a problem, if you are having issues with manifest files not being detected or uploaded files not being detected, setting this in your php.ini file might fix the issue.”

Okay here is the solution to remove this message

1. Create a php.ini file in the root folder of your Joomla web site
2. Add your temp directory path to it. It will be like this: upload_tmp_dir = /home/youraccontname/public_html/tmp
3. (Optional) Add a line to your .htaccess file so that your site can use the php.ini file. Add this line to .htaccess

SetEnv PHPRC /home/youraccountname/public_html

Thanks,

Jaswant

MySQL – Fetch duplicate records


If your database table having duplicate records and you want to remove all duplicates, this query will help you to find out duplicate records in a table. You can check the records based on any specific field.

SELECT *
FROM mdl_user
WHERE email IN (
	SELECT email
	FROM mdl_user
	GROUP BY email
	HAVING count(email) > 1
	)
ORDER BY email

This query will find all the records in mdl_user table having duplicate emails.

Cheers,
Jaswant

Follow

Get every new post delivered to your Inbox.