Docs / Troubleshooting / Performance Optimization

Performance Optimization

Overview

This guide covers techniques to optimize WordPress Download Manager performance, reduce server load, and improve download speeds. Follow these recommendations to ensure your download site handles traffic efficiently.

Performance Checklist

Quick wins for immediate improvement:

□ Enable page caching (exclude download URLs)
□ Optimize database tables
□ Use CDN for file delivery
□ Enable GZIP compression
□ Optimize images and thumbnails
□ Clean up old statistics data
□ Use object caching (Redis/Memcached)
□ Minimize plugins

Server Configuration

PHP Settings

Optimize PHP for large file handling:

// php.ini or .htaccess

// Memory
memory_limit = 256M

// Upload limits
upload_max_filesize = 512M
post_max_size = 512M

// Execution time
max_execution_time = 300
max_input_time = 300

// Output buffering
output_buffering = Off

// For large files
realpath_cache_size = 4M
realpath_cache_ttl = 600

.htaccess for Apache:

# PHP settings
php_value memory_limit 256M
php_value upload_max_filesize 512M
php_value post_max_size 512M
php_value max_execution_time 300

# Enable GZIP

    AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json


# Browser caching

    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"

Nginx configuration:

# Increase timeouts for large files
client_max_body_size 512M;
client_body_timeout 300s;
send_timeout 300s;

# Enable GZIP
gzip on;
gzip_types text/plain text/css application/json application/javascript;

# Buffer settings
client_body_buffer_size 128k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;

MySQL Optimization

my.cnf settings:

[mysqld]
# InnoDB settings
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2

# Query cache (MySQL 5.7)
query_cache_type = 1
query_cache_size = 64M
query_cache_limit = 2M

# Connection settings
max_connections = 150
wait_timeout = 300

# Temporary tables
tmp_table_size = 64M
max_heap_table_size = 64M

WordPress Configuration

wp-config.php Optimizations

// Memory limits
define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');

// Reduce post revisions
define('WP_POST_REVISIONS', 5);

// Increase autosave interval
define('AUTOSAVE_INTERVAL', 300);

// Disable file editing
define('DISALLOW_FILE_EDIT', true);

// Optimize database
define('WP_ALLOW_REPAIR', true);

// Object cache (if using Redis/Memcached)
define('WP_CACHE', true);

Object Caching

Install object caching for faster database queries:

Redis:

# Install Redis
sudo apt install redis-server

# Install Redis PHP extension
sudo apt install php-redis

# Verify
redis-cli ping  # Should return PONG

WordPress configuration:

// wp-config.php
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_DATABASE', 0);

WPDM-Specific Optimizations

Download Delivery Method

Choose the appropriate delivery method based on your setup:

Settings → Downloads → Download Settings → Download Speed
Method Best For Performance
Direct Small files, static hosting Fastest
PHP Readfile Medium files, shared hosting Good
X-Sendfile Large files, dedicated server Best
X-Accel-Redirect Large files, Nginx Best

Enable X-Sendfile (Apache):

# .htaccess

    XSendFile On
    XSendFilePath /path/to/wp-content/uploads/download-manager-files

Enable X-Accel-Redirect (Nginx):

location /protected-downloads/ {
    internal;
    alias /path/to/wp-content/uploads/download-manager-files/;
}

Speed Limiter Configuration

Balance download speeds with server load:

Settings → Downloads → Download Speed

Recommendations:

Scenario Speed Limit Chunk Size
Shared hosting 500 KB/s 256 KB
VPS (2GB RAM) 2 MB/s 512 KB
Dedicated server 10 MB/s 1 MB
Unlimited bandwidth 0 (unlimited) 2 MB

Statistics Optimization

Statistics can slow down large sites. Optimize:

// Reduce statistics retention (functions.php or plugin)
add_filter('wpdm_stats_retention_days', function() {
    return 90; // Keep only 90 days
});

// Disable real-time stats for high-traffic
add_filter('wpdm_track_download', function($track, $package_id) {
    // Skip tracking for frequent downloaders
    $downloads_today = get_user_downloads_today();
    return $downloads_today < 100;
}, 10, 2);

Archive old statistics:

-- Create archive table
CREATE TABLE wp_ahm_download_stats_archive LIKE wp_ahm_download_stats;

-- Move old data (older than 6 months)
INSERT INTO wp_ahm_download_stats_archive
SELECT * FROM wp_ahm_download_stats
WHERE timestamp < DATE_SUB(NOW(), INTERVAL 6 MONTH);

-- Delete from main table
DELETE FROM wp_ahm_download_stats
WHERE timestamp < DATE_SUB(NOW(), INTERVAL 6 MONTH);

-- Optimize table
OPTIMIZE TABLE wp_ahm_download_stats;

Package Listing Performance

Optimize package queries:

// Limit default items per page
add_filter('wpdm_packages_query_args', function($args) {
    $args['posts_per_page'] = min($args['posts_per_page'], 20);
    return $args;
});

// Disable thumbnail generation on listing
add_filter('wpdm_package_data', function($package) {
    if (is_archive()) {
        unset($package['preview_images']);
    }
    return $package;
});

Caching Strategy

Page Caching

Configure your caching plugin to exclude WPDM URLs:

URLs to exclude from cache:

/download/*
/wpdm-package/*
/?wpdmdl=*
/?wpdmkey=*
/checkout/*
/cart/*

WP Super Cache rules:

// wp-content/wp-cache-config.php
$cache_rejected_uri = array(
    'download',
    'wpdm-package',
    'wpdmdl',
    'wpdmkey',
    'checkout',
    'cart'
);

W3 Total Cache:

Performance → Page Cache → Advanced → Never cache the following pages:
/download/*
/checkout/*
/cart/*

Browser Caching for Static Assets

# .htaccess - Cache WPDM assets

    Header set Cache-Control "max-age=31536000, public"

Object Caching for Package Data

// Cache package data (functions.php)
add_filter('wpdm_package_data', function($package, $id) {
    $cache_key = 'wpdm_package_' . $id;

    $cached = wp_cache_get($cache_key, 'wpdm');
    if ($cached !== false) {
        return $cached;
    }

    wp_cache_set($cache_key, $package, 'wpdm', 3600);
    return $package;
}, 10, 2);

// Clear cache on update
add_action('wpdm_after_save_package', function($id) {
    wp_cache_delete('wpdm_package_' . $id, 'wpdm');
});

CDN Integration

Setting Up CDN

Use a CDN to serve files faster globally:

Supported CDN providers:

  • CloudFlare
  • Amazon CloudFront
  • KeyCDN
  • BunnyCDN
  • StackPath

CloudFlare configuration:

  • Add site to CloudFlare
  • Configure page rules:
   *example.com/wp-content/uploads/*
   - Cache Level: Cache Everything
   - Edge Cache TTL: 1 month
   
  • Exclude dynamic URLs:
   *example.com/download/*
   - Cache Level: Bypass
   

Amazon CloudFront with S3:

// Configure in WPDM S3 settings
// Settings → Downloads → Amazon S3

// Use CloudFront URL for delivery
CloudFront URL: https://d123456.cloudfront.net

CDN for Thumbnails

Serve package thumbnails from CDN:

// Rewrite thumbnail URLs to CDN
add_filter('wpdm_package_data', function($package) {
    if (isset($package['thumbnail'])) {
        $package['thumbnail'] = str_replace(
            home_url('/wp-content/uploads/'),
            'https://cdn.example.com/wp-content/uploads/',
            $package['thumbnail']
        );
    }
    return $package;
});

Database Optimization

Regular Maintenance

Run weekly database optimization:

-- Optimize WPDM tables
OPTIMIZE TABLE wp_ahm_download_stats;
OPTIMIZE TABLE wp_ahm_emails;
OPTIMIZE TABLE wp_ahm_sessions;
OPTIMIZE TABLE wp_ahm_orders;
OPTIMIZE TABLE wp_ahm_licenses;

-- Optimize WordPress tables
OPTIMIZE TABLE wp_posts;
OPTIMIZE TABLE wp_postmeta;
OPTIMIZE TABLE wp_options;

Index Optimization

Add indexes for common queries:

-- Index for package lookups
ALTER TABLE wp_ahm_download_stats
ADD INDEX idx_package_date (pid, timestamp);

-- Index for user statistics
ALTER TABLE wp_ahm_download_stats
ADD INDEX idx_user_date (uid, timestamp);

-- Index for order lookups
ALTER TABLE wp_ahm_orders
ADD INDEX idx_status_date (order_status, date);

Clean Up Transients

-- Delete expired transients
DELETE FROM wp_options
WHERE option_name LIKE '%_transient_timeout_%'
AND option_value < UNIX_TIMESTAMP();

DELETE FROM wp_options
WHERE option_name LIKE '%_transient_%'
AND option_name NOT LIKE '%_transient_timeout_%';

Postmeta Optimization

-- Remove orphaned postmeta
DELETE pm FROM wp_postmeta pm
LEFT JOIN wp_posts p ON p.ID = pm.post_id
WHERE p.ID IS NULL;

-- Index package meta keys
CREATE INDEX idx_wpdm_meta ON wp_postmeta (meta_key(40))
WHERE meta_key LIKE '__wpdm_%';

File System Optimization

Organize Upload Directory

Structure for better performance:

wp-content/uploads/download-manager-files/
├── 2026/
│   ├── 01/
│   │   ├── package-123/
│   │   └── package-124/
│   └── 02/
└── cache/
    ├── thumbnails/
    └── previews/

Enable Direct File Access

For large files, use direct linking when possible:

// Skip PHP for authorized downloads
add_filter('wpdm_download_url', function($url, $package_id) {
    if (current_user_can('manage_options')) {
        // Direct file URL for admins
        $files = get_post_meta($package_id, '__wpdm_files', true);
        return $files[0] ?? $url;
    }
    return $url;
}, 10, 2);

File Compression

Pre-compress large packages:

// Auto-compress on package save
add_action('wpdm_after_save_package', function($package_id) {
    $files = get_post_meta($package_id, '__wpdm_files', true);

    if (count($files) > 5 && !has_zip_file($files)) {
        // Create compressed version
        create_package_zip($package_id, $files);
    }
});

Monitoring Performance

Built-in Monitoring

Enable WPDM debug mode:

// wp-config.php
define('WPDM_DEBUG', true);
define('WPDM_LOG_PERFORMANCE', true);

Check logs:

wp-content/debug.log
wp-content/wpdm-performance.log

Query Monitor Plugin

Install Query Monitor to identify slow queries:

Slow queries related to WPDM:
- Package listing: Check wp_posts joins
- Statistics: Check ahm_download_stats queries
- User dashboard: Check user meta queries

Performance Benchmarks

Target metrics:

Metric Target Critical
Package listing < 200ms > 500ms
Single package < 100ms > 300ms
Download start < 50ms > 200ms
Admin dashboard < 500ms > 1s
Statistics page < 1s > 3s

New Relic / Application Monitoring

// Track WPDM-specific transactions
add_action('wpdm_before_download', function($package_id) {
    if (extension_loaded('newrelic')) {
        newrelic_name_transaction('WPDM/Download/' . $package_id);
    }
});

High-Traffic Optimization

Load Balancing

For sites with heavy download traffic:

                    ┌─────────────┐
                    │ Load        │
                    │ Balancer    │
                    └──────┬──────┘
           ┌───────────────┼───────────────┐
           ▼               ▼               ▼
    ┌──────────┐    ┌──────────┐    ┌──────────┐
    │ Web      │    │ Web      │    │ Web      │
    │ Server 1 │    │ Server 2 │    │ Server 3 │
    └────┬─────┘    └────┬─────┘    └────┬─────┘
         │               │               │
         └───────────────┼───────────────┘
                         ▼
              ┌────────────────────┐
              │ Shared File Storage│
              │ (NFS/GlusterFS/S3) │
              └────────────────────┘

Session Management

For multiple servers:

// Use database sessions
define('WP_SESSION_HANDLER', 'database');

// Or Redis sessions
define('WP_SESSION_HANDLER', 'redis');
define('WP_REDIS_SESSION_HOST', '127.0.0.1');

Queue Download Processing

For very large files:

// Queue downloads instead of immediate processing
add_filter('wpdm_download_method', function($method, $package_id) {
    $file_size = get_package_file_size($package_id);

    if ($file_size > 500 * 1024 * 1024) { // > 500MB
        return 'queued';
    }

    return $method;
}, 10, 2);

Troubleshooting Slow Performance

Common Issues

1. Slow Package Listing

Cause: Too many packages loading at once
Solution: Enable pagination, limit to 20 items

2. High Memory Usage

Cause: Large files loaded into memory
Solution: Use X-Sendfile/X-Accel-Redirect

3. Database Timeouts

Cause: Large statistics table
Solution: Archive old data, add indexes

4. Slow Admin Dashboard

Cause: Stats calculations on every load
Solution: Cache stats, use async loading

Debug Queries

// Log slow WPDM queries
add_filter('posts_request', function($sql) {
    if (strpos($sql, 'wpdm') !== false) {
        error_log('WPDM Query: ' . $sql);
        error_log('Time: ' . timer_stop());
    }
    return $sql;
});

Related Documentation


Last updated: January 2026
Applies to: WordPress Download Manager 7.x

Last updated on January 26, 2026

Need Help?

Get support from our team or community forum.

Visit Support

Customization

Need custom features? We can help.

Request Quote