Support

Account

Home Forums General Issues Very slow work

Solving

Very slow work

  • Hello. I have a big problem with slowly works my webpage. I work on latest WP + ACF, and Repeated Field. I’m not sure, that my solution is good, but I use loop as:

    <div>
    <?php if(get_field('machine',100)): ?>
    <?php while(has_sub_field('machine',100)): ?>       
    <?php $thumb = wp_get_attachment_image_src(get_sub_field('photo'), 'thumbnail'); ?>
    <?php $model = get_sub_field('model'); $model = preg_replace('/[\s\W]+/', '-', $model); $model = strtolower($model);  ?>
    
    <a href="/machine-<?php the_field('serie',100); ?>#<?php the_sub_field('serie'); ?>-<?php echo $model; ?>" rel="slidingtabs1" class="st_ext">
    <img src="<?php echo $thumb[0]; ?>" /><?php the_sub_field('serie'); ?> <?php the_sub_field('model'); ?>
    </a>
    
    <?php endwhile; ?>
    <?php endif; ?>
    </div>
    
    <div>
    <?php if(get_field('machine',101)): ?>
    <?php while(has_sub_field('machine',101)): ?>       
    <?php $thumb = wp_get_attachment_image_src(get_sub_field('photo'), 'thumbnail'); ?>
    <?php $model = get_sub_field('model'); $model = preg_replace('/[\s\W]+/', '-', $model); $model = strtolower($model);  ?>
    
    <a href="/machine-<?php the_field('serie',101); ?>#<?php the_sub_field('serie'); ?>-<?php echo $model; ?>" rel="slidingtabs1" class="st_ext">
    <img src="<?php echo $thumb[0]; ?>" /><?php the_sub_field('serie'); ?> <?php the_sub_field('model'); ?>
    </a>
    
    <?php endwhile; ?>
    <?php endif; ?>
    </div>
    
    <?php if(get_field('machine',102)): ?> ...............................................

    etc.

    And so about 12 reps. In every “machine” field, is about 10 models, with 7 subfields per model. Every “machine” section, is as separate post page.
    As I wrote, it works very slowly. “Time to first byte” takes circa 11-13 second every page load, tested on few servers. Every load, about 300 queries to db.
    On ACF code examples page, I found “Working with the Repeater Field” section, and methods of use them. Hence my question: Whether my code is constructed well?

    ps. Very sorry for my weak english.

  • Hi @danield

    Your code looks fine and your server should not be having troubles with this loop.
    Perhaps you could try setting up your website ‘locally’ on MAMP to test the code.

    If your code runs fine locally, then the issue is with your server. Every server is different, and perhaps your current one does not like many separate SQL queries on a page load.

    Thanks
    E

  • Hi! I’d suggest also checking what your thumbnail sizes are set to as if they could be causing the page to load slowly.

    You can find this option in your WordPress Admin area and navigate to Settings -> Media and you’ll see the options to change the sizes.

    Harry.

  • Hello. Thanks for reply. Page was testes on many hostings, and everywhere is the same problem. I have reply from last one, the problem is in one of my scripts “which enters into directories”, which causes the loop:
    /home/tema/domains/xyx.com/public_html/wp-content/uploads
    /home/tema/domains/xyx.com/public_html/wp-content
    /home/tema/domains/xyx.com/public_html
    /home/tema/domains/xyx.com
    /home/tema/domains
    /home/tema
    /home
    ..
    /home/tema/domains/xyx.com/public_html/wp-content/uploads
    /home/tema/domains/xyx.com/public_html/wp-content
    /home/tema/domains/xyx.com/public_html
    /home/tema/domains/xyx.com
    /home/tema/domains
    /home/tema
    /home
    .. and so on
    … and it takes about 10 seconds.
    When I turn odd ACF plugin, of course site doesnt’t look correct, but loads in one second.

  • Dimensions of thumbnails are set well

  • Hi @danield

    What do you mean by:
    “I have reply from last one, the problem is in one of my scripts “which enters into directories””

    If you have a reclusive script, then this would explain the infinite loop / wait time.

    Perhaps disabling ACF caused your code to not run, and prevent the infinite lopp code from running.

  • I got the answer from one of the hosting porovider, that the problem is in the script on my page, that cause loops.
    I do not understand what it means “reclusive script”.
    I think, problem is with ACF script, or maybe my ACF code above, which cause incorrect loop. Question is: where?

  • Hi @danield

    Can you please debug your code line by line to find out where the issue is?

    a simple debug method is this:

    
    <?php 
    
    $variable = 'somthing';
    
    echo '<pre>';
    	print_r($vairable);
    echo '</pre>';
    die;
    
    ?>
    

    The print_r / die will stop the page from running and display the contents of a variable. You can use this to check the dat on each line of your code.

    Perhaps also simplify your code to just 1 loop and remove all code from within the loop.

    Removing block of code is a quick way to find the line which causes the issue.
    Continue removing code until the issue is fixed. Then you can experiment with debugging to figure out why that line is the problem.

    If this is to hard, please consider hiring a freelancer to debug your code.

    Thanks
    E

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Very slow work’ is closed to new replies.