0

I have an issue with php 7.2 on my wordpress site . My host currently running on php 5.6 and after wordpress send notice that you need to upgrade your php version to 7.2 Cpu usage of my host increased to 90% !!! Thats a huge bug of wordpress

But now i'm gonna upgrade php to 7.2 but after upgrading every thing works fine except searching between products ! When my users using search box trying to find something after wordpress crashes and display this error :
The site is experiencing technical difficulties

The log Stored these lines of error :

#0 /home/censured-site/public_html/wp-includes/template.php(724): require()
#1 /home/censured-site/public_html/wp-includes/template.php(671): load_template('/home/censured...', false)
#2 /home/censured-site/public_html/wp-includes/general-template.php(168): locate_template(Array, true, false)
#3 /home/censured-site/public_html/wp-content/themes/mytheme/search-download.php(89): get_template_part('includes/loop-s...')
#4 /home/censured-site/public_html/wp-includes/template.php(724): require('/home/censured...')
#5 /home/censured-site/public_html/wp-includes/template.php(671): load_template('/home/censured...', false)
#6 /home/censured-site/public_html/wp-includes/general-template.php(168): locate_template(Array, true, false)
#7 /home/censured-site/public_html/wp-content/themes/mytheme/search.php(12): get_template_part('search', 'download')
#8 /home/censured-site/publ in /home/censured-site/public_html/wp-content/themes/mytheme/includes/loop-shop-listings.php on line 24

This is my whole loop-shop-listings.php:

   $eddColumn=get_theme_mod('olam_edd_columns');
  // var_dump($eddColumn);
   switch ($eddColumn) {
    case '2 columns':
    $colsize=6;
    $division=2;
    $colclass="col-sm-6";
    break;
    case '3 columns':
    $colsize=4;
    $division=3;
    $colclass="col-sm-3";
    break;
    case '4 columns':
    $colsize=3;
    $division=4;
    $colclass="col-sm-6";
    break;
    default:
    $colclass="col-sm-3";
    break;
   }
   if(($wp_query->current_post)%($division)==0){ echo "<div class='row'>"; } ?>
   <div class="col-md-<?php echo $colsize; ?> <?php echo $colclass; ?>">
    <div class="edd_download_inner">
        <div class="thumb">
            <?php $videoCode=get_post_meta(get_the_ID(),"download_item_video_id"); 
            $audioCode=get_post_meta(get_the_ID(),"download_item_audio_id");
            if(isset($videoCode[0]) && (strlen($videoCode[0])>0) ){
                // if(is_numeric($videoCode[0])){
                  //     $videoUrl=wp_get_attachment_url($videoCode[0]);
                  // }
                  // else{
                       $videoUrl=$videoCode[0]; 
                  // }
               //$videoUrl=wp_get_attachment_url($videoCode[0]);  

                if (strpos($videoUrl, 'vimeo') !== false) {
              echo '<div class="media-thumb vimeovid">'.do_shortcode("[video src='".esc_url($videoUrl)."' muted='1']").'</div>';
          } else {
              echo '<div class="media-thumb othervid">'.do_shortcode("[video src='".esc_url($videoUrl)."']").'</div>';
          }

            }
            else if(isset($audioCode[0]) && (strlen($audioCode[0])>0) ){
                $audioUrl=wp_get_attachment_url($audioCode[0]);
                ?>
                <div class="media-thumb">
                    <?php echo do_shortcode("[audio src='".$audioUrl."']"); ?>
                </div><?php
            } ?>
            <a href="<?php the_permalink(); ?>"><span><i class="demo-icons icon-link"></i></span>
                <?php $square_img = get_post_meta(get_the_ID(),"download_item_square_img");
                  if (!empty($square_img) && strlen($square_img[0])>0) {
                    echo '<img src="' . esc_url($square_img[0]) .'" />';
                  }
                  elseif ( has_post_thumbnail() ) {
                    the_post_thumbnail('olam-product-thumb');
                }
                else {
                    echo '<img src="' . get_template_directory_uri(). '/img/thumbnail-default.jpg" />';
                }
                ?>
            </a>
        </div>      
        <div class="product-details">
            <?php   $defaultPriceID=edd_get_default_variable_price( get_the_ID() ); ?>
            <div class="product-name"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
            <div class="product-price"><?php edd_price(get_the_ID(),true,$defaultPriceID); ?></div>
            <?php if ( has_excerpt() ) : // Only show custom excerpts not autoexcerpts ?>
               <p class="olam-custom-excerpt"><?php echo get_the_excerpt(); ?></p>
            <?php endif; ?>
            <div class="details-bottom">
                <div class="product-options">
                    <a href="<?php the_permalink(); ?>" title="<?php esc_attr_e('View','olam'); ?> "><i class="demo-icons icon-search"></i></a>                                            

                    <?php  if(!olam_check_if_added_to_cart(get_the_ID())){
                        $eddOptionAddtocart=edd_get_option( 'add_to_cart_text' );
                        $addCartText=(isset($eddOptionAddtocart) && $eddOptionAddtocart  != '') ?$eddOptionAddtocart:esc_html__("Add to cart","olam");
                        if(edd_has_variable_prices(get_the_ID())){

                            $downloadArray=array('edd_action'=>'add_to_cart','download_id'=>$post->ID,'edd_options[price_id]'=>$defaultPriceID);
                        }
                        else{
                            $downloadArray=array('edd_action'=>'add_to_cart','download_id'=>$post->ID);
                        }
                        ?>  
                        <a href="<?php echo esc_url(add_query_arg($downloadArray,edd_get_checkout_uri())); ?>" title="<?php esc_attr_e('Buy Now','olam'); ?>"><i class="demo-icons icon-download"></i></a>
              <?php
              $purchase_link_args = array(
                'download_id' => get_the_ID(),
                'price' => false,
                'direct' => false,
                'style' => 'plain',
                'class' => 'demo-icons icon-cart cart-icon-btn',
                'text' => '',
              );
              $purchase_link_args = apply_filters( 'edd_rp_purchase_link_args', $purchase_link_args );
              echo edd_get_purchase_link( $purchase_link_args );
              } else { ?>
                        <a class="cart-added" href="<?php echo edd_get_checkout_uri(); ?>" title="<?php esc_attr_e('Checkout','olam'); ?> "><i class="fa fa-check"></i></a>    
                        <?php } ?>
                    </div>

                    <?php $olamct=get_theme_mod('olam_show_cats');
                        if(isset($olamct)&& $olamct==1 ){
                    $cat = wp_get_post_terms(get_the_ID(),'download_category');
                     if(count($cat)>0){
                    $mlink = get_term_link($cat[0]->slug,'download_category');
                    ?><div class="product-author"><a href="<?php echo $mlink; ?>"><?php echo($cat[0]->name); ?></a></div><?php
                   } }
                    else{
                    ?> <div class="product-author"><a href="<?php echo esc_url(add_query_arg( 'author_downloads', 'true', get_author_posts_url( get_the_author_meta('ID')) )); ?>"><?php esc_html_e("By","olam"); ?>: <?php the_author(); ?></a></div><?php
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>
    <?php if(($wp_query->current_post+1)%($division)==0){  echo "</div>"; }
    else if(($wp_query->current_post+1)==$wp_query->post_count ){ echo "</div>"; }```
please help me . Thanks
  • 1
    Just to clarify, you had large CPU usage on PHP 5.6, and updated to PHP 7.2. After updating to PHP 7.2 searching for products leads to a HTTP 500 error with "The site is experiencing technical difficulties"? Let me know if I understood correct! Also what does your PHP error log say? – Tom J Nowell Aug 30 at 14:28
  • @TomJNowell No ! I haven't any problem with php 5.6 before wordpress send message in wordpress dashboard that tell your site running in old wordpress version ! and after i got this message cpu increased unnormally and didn't getting below 50% percent ! – TheXrion Aug 30 at 14:51
  • @TomJNowell My answer updated by log errors that you asked for. Best Regards – TheXrion Aug 30 at 14:54
  • Thanks, your error is missing the message, and has just the stack trace, it looks like includes/loop-shop-listings.php has a problem on line 24 but it's not clear what the problem is without the error message – Tom J Nowell Aug 30 at 15:14
  • 1
    Add the lines 10–30 of that file to your question please. – fuxia Aug 30 at 15:52
2

I'm going to guess that PHP's settings have changed with the upgrade. Division by zero suggests some variable is not initialized (and is being dynamically typed as 0). The PHP manual has a lot of information on the changes between 5.x and 7.x. This bit on how variables are handled supports my hypothesis, especially if your theme was created before 7.x was released.

On the same lines, I am going to guess that PHP is running out of memory (because the new settings file sets the value too low by default for your theme). I am guessing this is the case because the lines from the error log do not appear to be FATAL but rather, WARNING (based on your comment). When PHP runs out of memory, it sometimes doesn't even have enough to write to the error log, which makes debugging this type of error very difficult.

I suggest you do three things:

  1. Contact the theme author and see if they have an updated version of the theme available (assuming it is not your own).
  2. Increase the amount of memory PHP can use to something like 64MB or even 128MB and see if you can reproduce the error. You can do this in a variety of ways. See this link for more info.
  3. Turn display_errors off and instead send them to a log file so your users don't see PHP errors when using the site. Put the code snippet below in wp-config.php just before the STOP EDITING HERE line:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
  • I've just posted Whole loop-shop-listings.php please check it for finding whats is the issue ! I though its for one or multiple css classes ! – TheXrion Aug 31 at 0:00
  • As I implied in my answer, division by zero is a WARNING and probably not stopping execution, just the last thing that appears in the logs. Have you tried increasing PHP's memory limit significantly? – Ted Stresen-Reuter Aug 31 at 8:12
  • No the cpu usage was for brute-force attack that controlled now . I removed the IF statement in the line 24 if(($wp_query->current_post)%($division)==0){ echo "<div class='row'>"; } ?> and in the line 192 <?php if(($wp_query->current_post+1)%($division)==0){ echo "</div>"; } to echo <div> in all conditions and it got fixed. – TheXrion Aug 31 at 12:33
  • Interesting. Please realize that you may be substituting one problem for another (incorrect display) and that at some point, in another context, the original problem may return. Best of luck. – Ted Stresen-Reuter Aug 31 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.