Performance Optimization
SLAED CMS is designed with a focus on high performance and efficient resource utilization. However, to achieve maximum site speed, you need to properly configure the system and server environment.
Table of Contents
Performance Analysis
Built-in Tools
SLAED CMS provides built-in tools for performance analysis:
- System Information -
systeminfo.php
- System characteristics, PHP/MySQL versions, resource usage - Compatibility Check -
check_compat.php
- System requirements analysis - File Write Test -
test_write.php
- File permissions and write speed test
External Tools
For more detailed analysis, you can use:
- Google PageSpeed Insights - Web page performance analysis
- GTmetrix - Comprehensive speed analysis
- Pingdom Tools - Site load time testing
- WebPageTest - Detailed performance analysis
PHP Optimization
php.ini Settings
For optimal SLAED CMS performance, use the following PHP configuration:
; Memory
memory_limit = 256M
; Execution time
max_execution_time = 300
max_input_time = 300
; File uploads
upload_max_filesize = 32M
post_max_size = 32M
max_file_uploads = 20
; OPcache (essential for performance)
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 60
opcache.save_comments = 0
opcache.fast_shutdown = 1
; Sessions
session.gc_maxlifetime = 86400
session.cookie_lifetime = 0
session.cookie_secure = 1
session.cookie_httponly = 1
session.cookie_samesite = "Strict"
; Security
expose_php = Off
display_errors = Off
log_errors = On
PHP Extensions
Required extensions for performance:
- OPcache - PHP bytecode caching
- mysqli - Optimized MySQL access
- gd - Image processing
- zip - Archive handling
Recommended extensions:
- APCu - In-memory user cache
- Redis - Distributed cache
- Memcached - High-performance cache
Database Optimization
MySQL/MariaDB Settings
Recommended settings for my.cnf:
[mysqld]
# Buffers
innodb_buffer_pool_size = 256M
innodb_log_buffer_size = 16M
key_buffer_size = 64M
# Logs
innodb_log_file_size = 64M
innodb_flush_log_at_trx_commit = 2
# Query cache
query_cache_type = 1
query_cache_size = 32M
query_cache_limit = 2M
# Connections
max_connections = 100
max_connect_errors = 10
# Optimization
skip-name-resolve
table_open_cache = 2000
table_definition_cache = 2000
Table Optimization
Regular table optimization:
-- Optimize all SLAED CMS tables
OPTIMIZE TABLE sl_users, sl_modules, sl_config, sl_blocks, sl_categories;
Caching
Built-in SLAED CMS Caching
SLAED CMS provides a multi-level caching system:
- Page Caching - Full HTML page caching with configurable lifetime
- CSS/JavaScript Caching - File merging and minification
- Block Caching - Individual block caching with separate lifetimes
Cache Configuration
In config/config_core.php
:
$conf = array(
// Block caching
'cache_b' => '1', // Enable block caching
'cache_d' => '7', // Cache days
'cache_t' => '3600', // Cache lifetime (seconds)
// CSS/JS caching
'cache_css' => '1', // CSS caching
'cache_script' => '1', // JavaScript caching
// Compression
'css_c' => '1', // CSS compression
'script_c' => '1', // JavaScript compression
'html_compress' => '1', // HTML compression
);
External Caching Systems
Redis
// Redis connection
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
// Caching functions
function cache_get_redis($key) {
global $redis;
return $redis->get($key);
}
function cache_set_redis($key, $data, $ttl = 3600) {
global $redis;
return $redis->setex($key, $ttl, $data);
}
Memcached
// Memcached connection
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);
// Caching functions
function cache_get_memcached($key) {
global $memcached;
return $memcached->get($key);
}
function cache_set_memcached($key, $data, $ttl = 3600) {
global $memcached;
return $memcached->set($key, $data, $ttl);
}
Web Server Optimization
Apache
Optimize .htaccess:
# Static file caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
# Compression
<IfModule mod_deflate.c>
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
</IfModule>
# ETags
<IfModule mod_headers.c>
Header unset ETag
FileETag None
</IfModule>
Nginx
Optimize Nginx configuration:
server {
# Static file caching
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg)$ {
expires 1M;
add_header Cache-Control "public, immutable";
add_header Vary "Accept-Encoding";
}
# Compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/javascript
application/xml+rss
application/json;
}
Image Optimization
Image Formats
Recommended formats:
- WebP - Modern format with better compression
- AVIF - Next generation image formats
- JPEG - For photographs
- PNG - For images with transparency
Automatic Optimization
SLAED CMS supports automatic image optimization:
// Image optimization on upload
function optimize_image($source, $destination, $quality = 85) {
$info = getimagesize($source);
switch ($info['mime']) {
case 'image/jpeg':
$image = imagecreatefromjpeg($source);
imagejpeg($image, $destination, $quality);
break;
case 'image/png':
$image = imagecreatefrompng($source);
imagepng($image, $destination, floor($quality/10)-1);
break;
case 'image/webp':
$image = imagecreatefromwebp($source);
imagewebp($image, $destination, $quality);
break;
}
imagedestroy($image);
}
CDN (Content Delivery Network)
CDN Integration
To use CDN, configure these parameters:
- Static Files
// In configuration
$conf['cdn_url'] = 'https://cdn.yoursite.com';
- Resource Connection
<link rel="stylesheet" href="https://cdn.yoursite.com/templates/default/theme.css">
<script src="https://cdn.yoursite.com/plugins/jquery/jquery.min.js"></script>
Lazy Loading
Lazy Loading for Images
Implementing lazy loading:
<!-- Images with lazy loading -->
<img data-src="image.jpg" alt="Description" class="lazy" loading="lazy">
// JavaScript for lazy loading
document.addEventListener("DOMContentLoaded", function() {
const lazyImages = [].slice.call(document.querySelectorAll("img.lazy"));
if ("IntersectionObserver" in window) {
let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
let lazyImage = entry.target;
lazyImage.src = lazyImage.dataset.src;
lazyImage.classList.remove("lazy");
lazyImageObserver.unobserve(lazyImage);
}
});
});
lazyImages.forEach(function(lazyImage) {
lazyImageObserver.observe(lazyImage);
});
}
});
Performance Monitoring
Performance Logging
Enable execution time logging:
// In configuration
$conf['log_performance'] = 1;
$conf['performance_threshold'] = 1000; // ms
// Logging slow queries
function log_slow_query($query, $time) {
global $conf;
if ($time > $conf['performance_threshold']) {
error_log("Slow query: {$query} ({$time}ms)", 3, LOGS_DIR.'/performance.log');
}
}
Alerting
Configure performance issue notifications:
// Send alerts
function send_performance_alert($issue, $details) {
$subject = "Performance Alert: {$issue}";
$message = "Performance issue detected:\n\n{$details}";
mail(ADMIN_EMAIL, $subject, $message);
}
Scaling
Horizontal Scaling
For high-traffic sites:
- Load Balancing
upstream slaed_backend {
server 192.168.1.10:8080;
server 192.168.1.11:8080;
server 192.168.1.12:8080;
}
- Database Splitting - Master-slave replication, table sharding
Vertical Scaling
Increase server resources:
- More powerful processor
- More RAM
- SSD storage
- Dedicated server
Optimization Recommendations
Checklist
- Enable and configure OPcache
- Optimize PHP settings
- Configure MySQL caching
- Enable SLAED CMS caching
- Optimize images
- Use CDN for static files
- Enable Gzip compression
- Configure browser caching
- Implement lazy loading
- Conduct load testing
Regular Maintenance
Weekly
- Database table optimization
- Log cleanup
- Cache verification
Monthly
- Performance analysis
- PHP and MySQL updates
- Backup
Quarterly
- Code audit
- Security check
- Extension updates
By following these recommendations, you can achieve maximum performance for your SLAED CMS site and ensure an excellent user experience.