• Resolved stanikub

    (@stanikub)


    Hi, every time I try to scan my library I get this error
    Oops! Our scan hit an error due to limited resources on your site.

    I have more than 100 thousand images in library. Is there no way to scan it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @stanikub

    I hope you’re well today!

    That’s a lot of images and given the fact that for each image there are always also additional smaller copies/versions of it created by WordPress – this makes a really huge amount.

    Smush itself doesn’t have such limits on that but in order to be able to correctly do optimization, it needs to “scan the library” which means it goes through the DB to read information about each and every image and check optimization information that it may have added previously as well as check file paths (for each version of the given image).

    With this amount of images it results in a big amount of DB queries and filesystem requests which may, indeed, require significant resources. In general, the issue here is exactly what the error says – the resources provided by the server that hosts the site seem to be not sufficient to perform such a big scan.

    To deal with that, there are few things that you can try:

    1. Memory limit

    a) please go to the “Tools -> Site Health -> Info” page and check current value for “PHP memory limit” under “Server” tab; note it down.

    b) then look into the “WordPress Constants” tab on the same page and check current value for “WP_MEMORY_LIMIT” and “WP_MAX_MEMORY_LIMIT”

    c) if any of these two is smaller than the “PHP Memory limit” value, add following line(s) to the “wp-config.php”, accordingly, above the “/* That’s all, stop editing! */ line

    define( 'WP_MEMORY_LIMIT', 'XXX' );
    define( 'WP_MAX_MEMORY_LIMIT', 'XXX' );

    where XXX should be replaced with the value that you noted down in step 1a.

    Note: add these lines if in step 1a you see values lower than that from step 1a;

    2. If this doesn’t help, try also adding this line to the “wp-config.php” file (again, above the “/* That’s all, stop editing !*/”:

    define( 'WP_SMUSH_SCAN_SLICE_SIZE', '500' );

    This should help make scan less “aggressive” which may help (though it would make it slower).

    3. If none of that helps, a “last resort” option would be to use Directory Smushing instead of bulk-smushing to bulk-optimize those images.

    In this case, you can’t, unfortunately, select those media library folders directly from Directory Smush (you could select /wp-content/upload but it would still exclude the actual Media Library folders) so you would first need to “unlock” those folders.

    This can be done with a bit of custom code:

    <?php 
    
    add_filter( 'wp_smush_skip_folder', function( $skip, $path ) {
    	
    	$to_unlock = array( '2012', '2019', '2020' );
    	
    	$upload_dir = wp_upload_dir();
    	$base_dir   = $upload_dir['basedir'];
    	
    	
    	foreach ( $to_unlock as $key=>$value ) {
    		if ( false !== strpos( $path, $base_dir . '/' . $value ) ) {
    			$skip = false;
    		}
    	}
        
        return $skip;
    }, 10, 2 );

    In this code in this line

    $to_unlock = array( ‘2012’, ‘2019’, ‘2020’ );

    you would need to add all the “yearly” media library folders that you want to be available in Directory Smush, just like you see in that example.

    And then:

    – create an empty file with a .php extension (e.g. “smush-unlock-media-library-directories.php”)
    – copy and paste code into it
    – upload the file to the “/wp-content/mu-plugins” folder of our site’s WordPress installation

    Once it’s done, you should be able to go to “Smush -> Directory Smush” and select your media library folders from them.

    This would let you mass-optimize all those images but please be aware that, while the optimization would be the same and would follow settings of the “bulk smush”, you wouldn’t see stats for optimization of those images – neither on the Media Library page, nor in Smush plugin itself. This would also be “irreversible” process unless you have a separate backup of those folders.

    Kind regards,
    Adam

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @stanikub,

    Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to re-open the thread if you need further assistance.

    Regards
    Nithin

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Unable to scan library’ is closed to new replies.