Plugin Directory

Changeset 3409784


Ignore:
Timestamp:
12/03/2025 03:56:01 PM (4 months ago)
Author:
instarank
Message:

Version 1.5.8: Fix memory exhaustion on large WordPress sites

  • Fixed 'Allowed memory size exhausted' errors during crawl operations
  • Adaptive batch size based on PHP memory limit (16MB: 3 pages, 32MB: 5, 64MB: 10, 128MB: 15, 256MB+: 25)
  • Added aggressive memory cleanup after processing each page
  • Improved support for hosts with limited PHP memory (16MB-128MB)
  • Response now includes memory_limit_mb and content_included for debugging
Location:
instarank/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • instarank/trunk/api/endpoints.php

    r3409755 r3409784  
    46234623        $include_content = $request->get_param('include_content') !== 'false';
    46244624
    4625         // Limit to reasonable batch size for memory management
    4626         // Increased from 100 to 200 for faster crawling
    4627         $limit = min($limit, 200);
     4625        // Adaptive memory-conscious batch size based on available PHP memory
     4626        // Detect memory limit and adjust batch size accordingly
     4627        $memory_limit = $this->get_memory_limit_bytes();
     4628
     4629        if ($memory_limit <= 16 * 1024 * 1024) {
     4630            // 16MB or less - very restrictive hosting (e.g., shared hosting)
     4631            $max_batch = 3;
     4632            $include_content = false; // Disable HTML content to save memory
     4633        } elseif ($memory_limit <= 32 * 1024 * 1024) {
     4634            // 32MB - basic shared hosting
     4635            $max_batch = 5;
     4636        } elseif ($memory_limit <= 64 * 1024 * 1024) {
     4637            // 64MB - standard shared hosting
     4638            $max_batch = 10;
     4639        } elseif ($memory_limit <= 128 * 1024 * 1024) {
     4640            // 128MB - typical WordPress hosting
     4641            $max_batch = 15;
     4642        } else {
     4643            // 256MB+ - VPS/dedicated hosting
     4644            $max_batch = 25;
     4645        }
     4646
     4647        $limit = min($limit, $max_batch);
    46284648
    46294649        // Get post types
     
    47264746                'schema' => $schema_data
    47274747            ];
     4748
     4749            // Free memory after each post to prevent exhaustion on large sites
     4750            unset($html, $content, $meta, $internal_links, $content_images, $schema_data);
    47284751        }
    47294752
     
    47374760        $total_query = new WP_Query($count_args);
    47384761        $total_pages = $total_query->found_posts;
     4762
     4763        // Free total query memory
     4764        unset($total_query);
    47394765
    47404766        return rest_ensure_response([
     
    47524778                'wordpress_version' => get_bloginfo('version'),
    47534779                'plugin_version' => INSTARANK_VERSION,
    4754                 'seo_plugin' => $detector->get_active_seo_plugin()
     4780                'seo_plugin' => $detector->get_active_seo_plugin(),
     4781                'memory_limit_mb' => round($memory_limit / (1024 * 1024)),
     4782                'content_included' => $include_content
    47554783            ]
    47564784        ]);
     
    49294957
    49304958    /**
     4959     * Get PHP memory limit in bytes
     4960     * Parses the ini value and converts shorthand notation (e.g., 128M) to bytes
     4961     *
     4962     * @return int Memory limit in bytes (-1 if unlimited)
     4963     */
     4964    private function get_memory_limit_bytes() {
     4965        $memory_limit = ini_get('memory_limit');
     4966
     4967        if ($memory_limit === '-1') {
     4968            return PHP_INT_MAX; // Unlimited
     4969        }
     4970
     4971        $memory_limit = trim($memory_limit);
     4972        $last = strtolower($memory_limit[strlen($memory_limit) - 1]);
     4973        $memory_limit = (int) $memory_limit;
     4974
     4975        switch ($last) {
     4976            case 'g':
     4977                $memory_limit *= 1024;
     4978                // fall through
     4979            case 'm':
     4980                $memory_limit *= 1024;
     4981                // fall through
     4982            case 'k':
     4983                $memory_limit *= 1024;
     4984        }
     4985
     4986        return $memory_limit;
     4987    }
     4988
     4989    /**
    49314990     * Extract headings from content
    49324991     */
  • instarank/trunk/instarank.php

    r3409755 r3409784  
    44 * Plugin URI: https://instarank.com/wordpress-plugin
    55 * Description: Connect your WordPress site to InstaRank for AI-powered SEO optimization, schema markup generation, and programmatic SEO. Create and sync custom post types, automatically apply SEO improvements, and generate structured data with InstaRank's AI engine.
    6  * Version: 1.5.7
     6 * Version: 1.5.8
    77 * Author: InstaRank
    88 * Author URI: https://instarank.com
     
    1818
    1919// Define plugin constants
    20 define('INSTARANK_VERSION', '1.5.7');
     20define('INSTARANK_VERSION', '1.5.8');
    2121define('INSTARANK_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2222define('INSTARANK_PLUGIN_URL', plugin_dir_url(__FILE__));
  • instarank/trunk/readme.txt

    r3409755 r3409784  
    44Requires at least: 5.6
    55Tested up to: 6.8
    6 Stable tag: 1.5.7
     6Stable tag: 1.5.8
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    159159== Changelog ==
    160160
     161= 1.5.8 =
     162* Performance: Fixed memory exhaustion on large WordPress sites (1000+ pages)
     163* Performance: Reduced crawl batch size from 200 to 25 pages for better memory management
     164* Performance: Added aggressive memory cleanup after processing each page
     165* Compatibility: Improved support for hosts with limited PHP memory (16MB-128MB)
     166* Fix: Resolved "Allowed memory size exhausted" errors during crawl operations
     167
    161168= 1.5.7 =
    162169* Enhancement: Improved Knowledge Base generation with comprehensive data extraction
Note: See TracChangeset for help on using the changeset viewer.