When try to open

When try to open the Smush page (Media -> Smush) site gives a 502 error

  • Lindeni Mahlalela

    Hello amit_chhangani,

    I hope you are doing great today. Thank you for your patience and sorry for the inconveniences that this issue may have caused and we hope to resolve it soon.

    After looking at the error and debug logs, the following entry in debug log suggests Smush is limited as to number of queries it can make:

    Cannot access property on non-object in /<DOCUMENT_ROOT>/wp-includes/class-wp-query.php on line 3857

    The developer has suggested we try the following code to decrease the limit from Smush's default 2000 to a lower number, I have chosen 1000 but you can set it lower or a little higher but below 2000, say 1500 for example.

    add_filter('wp_smush_query_limit', 'decrease_smush_query_limit', 99, 1 );
    function decrease_smush_query_limit( $limit ) {
    	$limit =  1000;
    	return $limit;
    }

    You should add this code to your theme's 'functions.php' file or create a new file call it 'decreas-smush-query-limit.php' and include the follwoing content:

    <?php
    //paste the above code here

    Save the file and upload it to your website in the folder 'wp-content/mu-plugins' so you will have the file in the location:

    /public/wp-content/mu-plugins/decreas-smush-query-limit.php

    This file will be executed automatically as a plugin but without the need to activate it. This should get rid of the errors regarding query limit and should in turn solve the issue at hand.

    Please do this change, run a test and let us know the results. We will be happy to know it worked but we will be more than happy to assist if you still need any further help.

    Have a nice day.
    Mahlamusa

  • Lindeni Mahlalela

    Hello amit_chhangani,

    I hope you are doing great today. Thank you for your feedback and I am sorry that code did not work for you and I would love to help make it work.

    I would love to check your setup and see if there is anything I can do to help. Would you please enable support access and share your FTP details so I can check your setup and hopefully will find a solution soon.

    You can share your FTP details via our secure contact form, make the subject "Attn: Lindeni Mahlalela" and include the FTP host, username and password in the Message box, also include a link to this thread for reference.

    I hope to hear back from you soon.

    Have a nice day.
    Mahlamusa

  • amit_chhangani

    In the Error log we found this:

    [Tue Aug 22 07:34:56 2017] [hphp] [57497:7fa9c5fff700:393:000010] [] SlowTimer [2080ms] at runtime/ext_mysql: slow query: SELECT   wp_posts.* FROM wp_posts  INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1  AND ( \n  ( wp_postmeta.meta_key = 'wp-smush-lossy' AND wp_postmeta.meta_value = '1' )\n) AND wp_posts.post_type = 'attachment' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft' AND wp_posts.post_status <> 'spam' AND wp_posts.post_status <> 'orphan' AND wp_posts.post_status <> 'hidden')) GROUP BY wp_posts.ID ORDER BY wp_posts.ID DESC LIMIT 40000, 2000
    
    [Tue Aug 22 07:34:58 2017] [hphp] [57497:7fa9c5fff700:393:000011] [] SlowTimer [1937ms] at runtime/ext_mysql: slow query: SELECT   wp_posts.* FROM wp_posts  INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1  AND ( \n  ( wp_postmeta.meta_key = 'wp-smush-lossy' AND wp_postmeta.meta_value = '1' )\n) AND wp_posts.post_type = 'attachment' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft' AND wp_posts.post_status <> 'spam' AND wp_posts.post_status <> 'orphan' AND wp_posts.post_status <> 'hidden')) GROUP BY wp_posts.ID ORDER BY wp_posts.ID DESC LIMIT 42000, 2000
  • Lindeni Mahlalela

    Hello amit_chhangani,

    I am sorry to hear that this is not working for you. Unfortunately it will be hard for us ti debug without the FTP details. What you can do is share with us how you applied the code snippet on your site.

    How did you use the snippet? Did you create an mu-plugin or placed the code in functions.php file. Please share screenshots of the ftp folder where you uploaded the code to, also share a screenshot of the contents of the file where the code is.

    Checking the LIMIT on the log entry you shared, it seems Smush is querying 2000 files at a time, after applying the fix this number should be reduced to the number specified in the code snippet. So, it seems to me that the code is not effective or it is not applied properly that is why we wanted to check by logging into your files through FTP.

    I hope this helps. Please let us know if you need any further assistance.

    Have a nice day,
    Mahlamusa

  • Lindeni Mahlalela

    Hello amit_chhangani,

    I hope you are doing great. I must say this will be a little harder to resolve if we work like this. But anyway, the log entries you shared last shows that the filter is not applied as it is still querying 2000 instead of the 1000 I suggested.

    When I requested the screenshot, I wanted to see the code as used in your functions.php. Another thing you can try is to change the priority of the filter in case another plugin is manipulating the query somehow. You can do so by changing the 99 to 999 or something bigger.

    add_filter('wp_smush_query_limit', 'decrease_smush_query_limit', 999, 1 );

    Since you can now access the Wp Smush Pro, please try to bulk smush and see how it goes.

    I hope this helps. Please let us know if this helps or if you still need help with this.

    Have a great day.
    Mahlamusa