Jump to content

Site is slow, cpu overusage and error log is spammed


Jack01

Recommended Posts

Hello, I'm trying to resolve a problem on a PrestaShop website, I'm a newbie on PrestaShop but I'm a experienced programmer so I think that I can solve it with your suggestions.

 

This is my configuration:

Versione di PHP: 5.6.30

Versione di Prestashop: 1.5.2.0

 

I'm having the issue both Front End and Back End, the whole site is slow and having problems.

 

Each request I make to the site pumps up the CPU usage to ~70% of the quota, and when there are many requests, I sporadically get some "HTTP 508 - Resource Limit Is Reached" due to my hosting provider limit.

 

So I enabled the log_errors on the PHP options on my cPanel and look at the errors, and there I got:

[13-Mar-2017 13:17:57 UTC] PHP Warning:  Memcache::getextendedstats(): No servers added to memcache connection in /home/cp22z7i2/public_html/classes/cache/CacheMemcache.php on line 50
[13-Mar-2017 13:17:57 UTC] PHP Warning:  Invalid argument supplied for foreach() in /home/cp22z7i2/public_html/classes/cache/CacheMemcache.php on line 52
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Undefined index: cms in /home/cp22z7i2/public_html/cache/smarty/compile/06f2957de2a296786fd4c08b9f288d1ed359cf8c.file.header.tpl.php on line 135
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Trying to get property of non-object in /home/cp22z7i2/public_html/cache/smarty/compile/06f2957de2a296786fd4c08b9f288d1ed359cf8c.file.header.tpl.php on line 135
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Trying to get property of non-object in /home/cp22z7i2/public_html/cache/smarty/compile/06f2957de2a296786fd4c08b9f288d1ed359cf8c.file.header.tpl.php on line 135
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Undefined index: cms in /home/cp22z7i2/public_html/cache/smarty/compile/00d3712b0a3ef8949448a5dc9031255370e2c7f8.file.footer.tpl.php on line 84
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Trying to get property of non-object in /home/cp22z7i2/public_html/cache/smarty/compile/00d3712b0a3ef8949448a5dc9031255370e2c7f8.file.footer.tpl.php on line 84
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Trying to get property of non-object in /home/cp22z7i2/public_html/cache/smarty/compile/00d3712b0a3ef8949448a5dc9031255370e2c7f8.file.footer.tpl.php on line 84
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Undefined property: Cart::$additional_shipping_cost in /home/cp22z7i2/public_html/cache/smarty/compile/00d3712b0a3ef8949448a5dc9031255370e2c7f8.file.footer.tpl.php on line 113
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Undefined index: total_to_pay in /home/cp22z7i2/public_html/cache/smarty/compile/00d3712b0a3ef8949448a5dc9031255370e2c7f8.file.footer.tpl.php on line 123
[13-Mar-2017 14:17:58 Europe/Rome] PHP Notice:  Trying to get property of non-object in /home/cp22z7i2/public_html/cache/smarty/compile/00d3712b0a3ef8949448a5dc9031255370e2c7f8.file.footer.tpl.php on line 123

this is repeat many times every second. When I turned on the errors the CPU usage has increased even more.

 

It is possible that the error reported are causing the slowness?

 

The first two lines seems to be a problem with memcache but I can see I have memcache and memcached extensions activated in my cPanel and installed as a PHP extension, so what?

 

The other lines seems to be related to errors inside cached and compiled template files. How I'm I supposed to debug the source of them?

 

Any help is appreciated, thanks.

post-1380075-0-71705400-1489434356_thumb.png

post-1380075-0-91157500-1489434364_thumb.png

post-1380075-0-33931800-1489434375_thumb.png

Link to comment
Share on other sites

No, I don't think I'm under flooding attack because my access logs looks fine, i believe it is just really CPU expensive to serve one single request. If I turn on the log_error it becomes even more intensive due to I/O operations.

I still have no idea what is wrong with memcache but I'm looking at the previuos error code lines thrown, as joseantgv suggested, and I see:

/* the error is here ---> */ <?php if ($_smarty_tpl->tpl_vars['cms']->value->id==4||$_smarty_tpl->tpl_vars['page_name']->value=="stores"){?>
                        <link href="prettyPhoto.css" rel="stylesheet" type="text/css"/>
                        <script type="text/javascript" src="jquery.prettyPhoto.js"></script>
<?php }?>

The error is that PHP is trying to get a value from "$_smarty_tpl" array indexing it with the unexisting key "cms" . So why is that value missing?

Is it related to memcache fault?

I checked the memcache configuration and i found that no additional server is setted up but maybe it is not mandatory?!

Edited by Jack01 (see edit history)
Link to comment
Share on other sites

I have solved most of the errors by adding some

 {if isset($variable_name)}...{/if}

where needed.

 

Now I'm facing the last error:

<b>Notice</b>:  Undefined index: desc in <b>/Users/jack/Documents/VirtualHosts/myPS/cache/smarty/compile/63c7bd8a8381e0bf807312c416fd08ef62f9af98.file.category-tree-branch.tpl.php</b> on line <b>34</b>

The problem now is different! If I edit the /themes/mytheme/category-tree-branch.tpl template nothing change in FO.

 

My Cache is OFF and force compile is ON. I deleted the compile folder too, but the server regenerates it as it was before the modification!

 

Any Idea? 

Thanks.

Link to comment
Share on other sites

I have solved most of the errors by adding some

 {if isset($variable_name)}...{/if}

where needed.

 

Now I'm facing the last error:

<b>Notice</b>:  Undefined index: desc in <b>/Users/jack/Documents/VirtualHosts/myPS/cache/smarty/compile/63c7bd8a8381e0bf807312c416fd08ef62f9af98.file.category-tree-branch.tpl.php</b> on line <b>34</b>

The problem now is different! If I edit the /themes/mytheme/category-tree-branch.tpl template nothing change in FO.

 

My Cache is OFF and force compile is ON. I deleted the compile folder too, but the server regenerates it as it was before the modification!

 

Any Idea? 

Thanks.

 

Maybe this template is in /themes/your-theme/modules?

Link to comment
Share on other sites

I've no module folder in this theme, but I have a mobile folder. But anyway I can't find the right file that generates the errored compiled one.

 

I searched for category-tree-branch.tpl recursively under /themes/mytheme/ and changed all the files I found in _category-tree-branch.tpl , deleted the /smarty/compile folder , and refreshed the page in FO. I expected a File not found error but instead the compiled file continue to be regenerated with the error inside as if I didn't change anythig.

 

What am I doing wrong???

Edited by Jack01 (see edit history)
Link to comment
Share on other sites

Found it!!!

 

It was category-tree-branch.tpl in /modules/blockcategory/ .

 

I had to change:

	<a href="{$node.link|escape:'htmlall':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if} title="{$node.desc|escape:'htmlall':'UTF-8'}">{$node.name|escape:'htmlall':'UTF-8'}</a>

to:

	<a href="{$node.link|escape:'htmlall':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if} title="{if 'desc'|array_key_exists:$node }{$node.desc|escape:'htmlall':'UTF-8'}{/if}">{$node.name|escape:'htmlall':'UTF-8'}</a>

Now there is just one last error!!!

[14-Mar-2017 15:14:25 UTC] PHP Warning:  Memcache::getextendedstats(): No servers added to memcache connection in /home/cp22z7i2/public_html/classes/cache/CacheMemcache.php on line 50
[14-Mar-2017 15:14:25 UTC] PHP Warning:  Invalid argument supplied for foreach() in /home/cp22z7i2/public_html/classes/cache/CacheMemcache.php on line 52

 

The incrimianated lines are the following:

        $all_slabs = $this->memcache->getExtendedStats('slabs');

        foreach ($all_slabs as $server => $slabs)
        {

Is it mandatory to add a server for memcache? 

Edited by Jack01 (see edit history)
Link to comment
Share on other sites

By the way, I mark this as closed as I found a final solution.

 

I think it has been a good practice to clear all the error that was being spammed out, but the real solution to make the site faster has been simply to enable Recompile templates if the files have been updated  instead of force compilation in Advanced Settings > Performance.

 

Thank you joseantgv for the help

  • Like 1
Link to comment
Share on other sites

By the way, I mark this as closed as I found a final solution.

 

I think it has been a good practice to clear all the error that was being spammed out, but the real solution to make the site faster has been simply to enable Recompile templates if the files have been updated  instead of force compilation in Advanced Settings > Performance.

 

Thank you joseantgv for the help

 

The less errors the better ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...