|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Fri Nov 09, 2012 3:51 pm Post subject: [Smarty3] random occurring fatal memory |
|
|
Hello,
I have an issue with Smarty 3 lately.
It is appearing time to time, I have no clue how it is happening so I wanted to stop by and ask others.
Error I am getting is
Quote: |
( ! ) Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 542115804 bytes) in X:\web\root\myfw\php\classes\smarty\sysplugins\smarty_internal_templatebase.php on line 161
Call Stack
# Time Memory Function Location
1 0.0005 333072 {main}( ) ..\index.php:0
2 0.0398 647256 core->render( ) ..\index.php:68
3 0.0398 647288 page->_render( ) ..\class.core.php:370
4 0.0403 659704 Smarty_Internal_TemplateBase->display( ) ..\class.page.php:234
5 0.0403 659832 Smarty_Internal_TemplateBase->fetch( ) ..\smarty_internal_templatebase.php:374
6 0.1217 1815656 eval( '?> tpl_vars['pageType']->value=="html"){?> getSubTemplate ("head.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?> tpl_vars['pv']->value['error']){?> getSubTemplate ("error.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?> getSubTemplate ("inc/header.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?> getSubTemplate ($_smarty_tpl->tpl_vars['pageTemplate']->value['body'], $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?> tpl_vars['pageType']->value=="html"){?> getSubTemplate ("inc/footer.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?> getSubTemplate ("tail.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?> tpl_vars['pageType']->value=="html"){?> ' ) ..\smarty_internal_templatebase.php:252
7 0.1217 1815928 Smarty_Internal_Template->getSubTemplate( ) ..\smarty_internal_templatebase.php(252) : eval()'d code:3
8 0.1218 1819680 Smarty_Internal_TemplateBase->fetch( ) ..\smarty_internal_template.php:286
|
System works as,
1)
Quote: |
class page extends Smarty {...}
|
2) Dynamic theme is assigned to $theme. then templateDirs are assigned.
Quote: |
$this->setTemplateDir(array(
'theme' => 'templates/' . $this->theme,
'core' => 'templates/_core',
'templates' => 'templates'
));
|
3) $pageTemplate['body'] is assigned by php. it can be page_aboutus.tpl / page_default.tpl or page_404.tpl
4) Display is processed by a sub function.
Quote: |
public function _render()
{
switch ($this->pageType)
{
case 'json':
$tpl = $this->getTemplateDir('core').'json.tpl';
$this->assign('json',json_encode($this->pageVariables['data']));
unset($this->pageVariables);
break;
case 'html' :
case 'inner' :
default :
$this->doAssignments(); /* this function makes $this->assign calls */
$tpl = $this->getTemplateDir('core').'body.tpl';
break;
}
$this->cache_id = md5($this->req['subdomain'].':'.$this->req['domain'].':'.$this->req['language'].':'.$this->req['cache'].':'.$this->req['pageFile'].':'.$this->req['pageUrl']);
return $this->display($tpl);
}
|
5) templates/_core/body.tpl as follows and included files are
_core/body.tpl -> http://pastebin.com/GAtKfDpe
That includes
A) in order - thanks to template ordering -
i) if theme has a "head.tpl" file
ii) if not templates/_core/head.tpl -> http://pastebin.com/Pnd6DARS
B) in order
i) templates/"theme"/inc/header.tpl
ii) if it does not exists it includes templates/_core/inc/header.tpl (which always exists)
C) $pageTemplate['body'] -> pages/page_default.tpl for example it also has default files in _core directory.
D) in order
i) templates/"theme"/inc/footer.tpl
ii) if it does not exists it includes templates/_core/inc/footer.tpl (which always exists)
E) in order
i) templates/"theme"/tail.tpl
ii) if it does not exists it includes templates/_core/tail.tpl (which always exists)
F) any dynamic javascript captured by {capture}
6) Smarty setup is:
Quote: |
$this->setCompileDir('tmp')
->setCacheDir('cache');
$this->force_compile = 0;
$this->caching = 1;
$this->compile_check = 1;
$this->cache_lifetime = -1;
$this->debugging = 0;
Smarty::muteExpectedErrors();
|
7) In conclusion, I am out of ideas. This error is happening once a while and repeating itself for 3-5 times in a row. and after it is returning to normal and serving data as it has to.
Any help or ideas are appreciated, I can give more code samples and structure information if it will be helpful. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Nov 10, 2012 7:38 am Post subject: |
|
|
Your memory_limit in the php.ini is set to 32M. This could be too low if a larger number of templates need to recompile at the same time.
This would also explain that the error disappears after some reloads. (It managed to recompile some of the subtemplates on each try. |
|
Back to top |
|
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Sat Nov 10, 2012 9:08 pm Post subject: |
|
|
Thanks a lot for the answer U.Tews. I will increase the memory_limit to 128M and 256M afterwards and see if error repeats itself. Cheers.
---
Edit:
I've managed to get same memory error with 128M setting.
Quote: |
[10-Nov-2012 21:19:03 UTC] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 542266428 bytes) in X:\webmaster\root\myfw\php\classes\smarty\sysplugins\smarty_internal_templatebase.php on line 161
[10-Nov-2012 21:19:03 UTC] PHP Stack trace:
[10-Nov-2012 21:19:03 UTC] PHP 1. {main}() X:\webmaster\root\myfw\index.php:0
[10-Nov-2012 21:19:03 UTC] PHP 2. core->render() X:\webmaster\root\myfw\index.php:74
[10-Nov-2012 21:19:03 UTC] PHP 3. page->_render() X:\webmaster\root\myfw\php\classes\class.core.php:370
[10-Nov-2012 21:19:03 UTC] PHP 4. Smarty_Internal_TemplateBase->display() X:\webmaster\root\myfw\php\classes\class.page.php:234
[10-Nov-2012 21:19:03 UTC] PHP 5. Smarty_Internal_TemplateBase->fetch() X:\webmaster\root\myfw\php\classes\smarty\sysplugins\smarty_internal_templatebase.php:374
[10-Nov-2012 21:19:03 UTC] PHP 6. content_509ec492b253f4_36345482() X:\webmaster\root\myfw\php\classes\smarty\sysplugins\smarty_internal_templatebase.php:281
[10-Nov-2012 21:19:03 UTC] PHP 7. Smarty_Internal_Template->getSubTemplate() X:\webmaster\root\myfw\cache\c0fc8520f4e2ea97bde06411ce1c66a7^28a234b347dbec190f15ba6ff931687ef14d17cc.body.tpl.php:69
[10-Nov-2012 21:19:03 UTC] PHP 8. Smarty_Internal_TemplateBase->fetch() X:\webmaster\root\myfw\php\classes\smarty\sysplugins\smarty_internal_template.php:286
|
c0fc8520f4e2ea97bde06411ce1c66a7^28a234b347dbec190f15ba6ff931687ef14d17cc.body.tpl.php --> http://pastebin.com/PBrxaD69
Line:69 is ->
Quote: |
<?php echo $_smarty_tpl->getSubTemplate ("head.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?>
|
cache: http://www.mediafire.com/?9pkbxiv690cnkx4
tmp: http://www.mediafire.com/?7il9w4vqcrilegw
phpinfo core section: http://pastebin.com/6mj7dtSy
After that error, if I try to refresh page, I am getting "text/html" download window popup,which tells me to download following 200 error:
http://pastebin.com/GQGLcfE0
Which has this response headers
Quote: |
Connection Keep-Alive
Content-Type application/x-httpd-php
Date Sat, 10 Nov 2012 21:34:40 GMT
Keep-Alive timeout=5, max=100
Server Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/0.9.8o
Transfer-Encoding chunked
X-UA-Compatible IE=Edge,chrome=1
|
After 2-3 refreshes of this download screen disappears and I am getting my -expected- output, with following response headers:
Quote: |
Connection Keep-Alive
Content-Type text/html;charset=UTF-8
Date Sat, 10 Nov 2012 21:34:46 GMT
Keep-Alive timeout=5, max=100
Server Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/0.9.8o
Transfer-Encoding chunked
Vary Accept-Encoding
X-Powered-By PHP/5.3.9-ZS5.6.0 ZendServer
X-UA-Compatible IE=Edge,chrome=1
|
And if I turn on debug and display what is included and going on:
Quote: |
Smarty Debug Console - Total Time 0,02996
included templates & config files (load time in seconds)
templates/_core/body.tpl (compile 0,00000) (render 0,00000) (cache 0,01105)
templates/_core/head.tpl (compile 0,00000) (render 0,00165) (cache 0,00000)
templates/ersev/inc/begin.tpl (compile 0,00000) (render 0,00000) (cache 0,00060)
templates/ersev/inc/header.tpl (compile 0,00000) (render 0,00036) (cache 0,00000)
templates/ersev/pages/page_default.tpl (compile 0,00000) (render 0,00040) (cache 0,00000)
templates/ersev/inc/footer.tpl (compile 0,00000) (render 0,00034) (cache 0,00000)
templates/_core/tail.tpl (compile 0,00000) (render 0,00381) (cache 0,00000)
templates/_core/inc/end.tpl (compile 0,00000) (render 0,00000) (cache 0,00047)
|
For whole list: http://pastebin.com/2H7Cgs6s
my .htaccess -> http://pastebin.com/nTZFMRFZ
What bothers me that, I have done various projects with Smarty2 before - one of them is a news website with force_compile = 1 setting and running on a 2gig ram machine (php memory_limit is 256M), having 30k~50k unique visitors with 1k visitor peak in some moments, and never had an issue like that) - and after switching to Smarty3 I have started to experience those behaviours. Code is really simple and I couldnt figure out where it can get that memory leak.
Either I am making a big mistake somewhere which is causing a memory loop, or I will try reverting back to Smarty2 and test it out there, which I am not willing to as Smarty3 seems more "smooth" for designers.
I will give it a shoot with 256M setting, but probably I will get that error in a way, as it is using up +512M somewhere I couldnt figure.. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Nov 10, 2012 11:26 pm Post subject: |
|
|
What looks strange to me that you have so many and big {nocache} sections in the template files.
For example in body.tpl. This does not make too much sense for me.
But it is still strange that PHP wants to allocate 542266428 bytes when including a compiled template.
Could you check for a very large compiled template file just when a page does fail at the first time? |
|
Back to top |
|
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Sun Nov 11, 2012 12:21 am Post subject: |
|
|
Thanks again for the rapid response U.Tews.
I do not have {nocache}s actually, just template variables are assigned with "nocache",
ie.
Quote: |
public function doAssignments()
{
$this->assign('lang', $this->lang);
$this->assign('req', $this->req, true);
$this->assign('action', $this->req['action'], true);
$this->assign('config', $this->config, true);
$basePath = $this->config['docroot'] . $this->getTemplateDir($this->base);
$themePath = $this->config['docroot'] . $this->getTemplateDir('theme');
$this->assign('theme', $this->theme);
$this->assign('location', $this->config['location']);
$this->assign('base', $this->base);
$this->assign('themePath', $themePath);
$this->assign('basePath', $basePath);
$this->assign('imagesDir', $this->config['cdn_host'] . $themePath . 'img/');
$this->assign('pageTemplate', $this->pageTemplate, true);
$this->assign('pagesByName', $this->pagesByName, true);
$this->assign('pageInfo', $this->pageInfo, true);
$this->assign('get', $this->_get, true);
$this->assign('post', $this->_post, true);
/* page vars */
$this->assign('pageName', $this->pageName, true);
$this->assign('pv', $this->pageVariables, true);
$this->assign('pageType', $this->pageType, true);
/* page modules */
$this->assign('pm', $this->pageModules, true);
$this->assign('debug_log', $this->debug, true);
return $this;
}
|
Purpose of those ",true" assignments is, that those variables should not be cached,as they are dynamic and generated from database. If I turn out caching on those variables, generated content seems to fail consistency (ie "contact" page variables showing up in "about us" page), I will try to alter those and see about nocache sections again.
body.tpl ( http://pastebin.com/GAtKfDpe ) did not have nocache sections either, so I do not know how this leak happening.
What makes me confused is, for example in "templates_c" folder (tmp in my version) I have a
71fb5ed76df6f5c13c64f923e8bb1d3f6130141f.file.head.tpl.php ->
http://pastebin.com/sUZ6b2Yi
this has ,
Quote: |
'variables' =>
array (
'pageInfo' => 1,
'config' => 1,
'basePath' => 0,
),
'has_nocache_code' => false,
|
whereas I am assigning $config/$pageInfo with ",true" parameter so they should not be cached.
and it is giving output as
Quote: |
<body class="page_<?php echo $_smarty_tpl->tpl_vars['pageInfo']->value['page_name'];?>
tpl_<?php echo $_smarty_tpl->tpl_vars['pageInfo']->value['page_file'];?>
|
Then, in 28a234b347dbec190f15ba6ff931687ef14d17cc.file.body.tpl.cache.php ->
( http://pastebin.com/9Jnh10Fv )
Quote: |
'variables' =>
array (
'pageType' => 1,
'pv' => 1,
'pageTemplate' => 1,
'cap' => 0,
),
'has_nocache_code' => true,
|
which looks as I expected as it has variables assigned which should not be cached.
and output comes as for example
Quote: |
<?php echo '/*%%SmartyNocache:12952509ec4924702c3-21986404%%*/<?php if ($_smarty_tpl->tpl_vars[\'pageType\']->value=="html"){?>/*/%%SmartyNocache:12952509ec4924702c3-21986404%%*/';?>
|
then I have no idea why this area comes with "nocache",
Quote: |
<?php echo '/*%%SmartyNocache:12952509ec4924702c3-21986404%%*/<?php echo $_smarty_tpl->getSubTemplate ("inc/header.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);?>
/*/%%SmartyNocache:12952509ec4924702c3-21986404%%*/';?>
|
Then still I am not getting how that can use up ~512mb memory.
I have checked my sql queries from database (with explain command attached - also using sql_cache after selects, all tables have required indexes and optimized queries) ,so sql layer is using minimum memory allocation possible. And php part I optimized as much as I can but it seems I am missing out something, either smarty related or it is on my side.
I will try to demonstrate the situation that you have mentioned, however biggest compiled file is body.tpl and size is 4kb in user area, rest are around that size too.
_core folder (tpl files only css/js/images omitted) & theme folder (tpl files only css/js/images omitted) http://www.mediafire.com/?p2nz65gf8ou8khb,8a7gq53x88l4dvr
they are very simple and complicated templates so having that much memory usage is something that I could not figure out.
Thanks a lot for your time again U.Tews |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Nov 11, 2012 1:08 am Post subject: |
|
|
{include file="inc/header.tpl"} is within the {if $pageType eq "html"} ... {/if}
So it's called also nocache.
It does not really make to much sense to assign $pageType as nocache and have so many subtemplates included in nocache mode. This has bad performance.
You are better off to have template sets for html and not html pages.
But this is a different story to your original problem.
Is the error is some way related to changes in template source? |
|
Back to top |
|
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Sun Nov 11, 2012 10:20 am Post subject: |
|
|
Thanks for the advice about $pageType, I will reconsider that part to optimize performance.
The error is appearing after changes in the template source. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Nov 11, 2012 1:17 pm Post subject: |
|
|
I'm running out of ideas what could cause this extreme memory allocation in your case. |
|
Back to top |
|
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Sun Nov 11, 2012 9:11 pm Post subject: |
|
|
Same here..
I have not come across with this error on production server myself yet. However if a visitor gets an error - or worse a search engine bot visits and gets page with error -, that wont be acceptable in my case.
Maybe it is just my development host , if it is an error that I am getting all the time I will understand and try debugging the source of it, frustating thing is, it is happening "when it wants". I am starting httpd/mysql services, then opening localhost (www.lvh.me) , and here we have memory error - sometimes without modifying any template even compiled and cached versions exists in folders -, or in the middle of editing template design, I am refreshing page to see changes , there exists memory error.
Dev server info as follows:
Quote: |
PHP Version 5.3.9-ZS5.6.0
(Windows 7 Ultimate Edition Service Pack 1) i586
Build Date Feb 23 2012 11:10:18
Compiler MSVC9 (Visual C++ 2008)
Architecture x86
Configure Command cscript /nologo configure.js "--disable-phar" "--disable-ipv6" "--disable-zts" "--enable-cgi" "--disable-bcmath" "--disable-calendar" "--disable-odbc" "--disable-tokenizer" "--disable-xmlreader" "--disable-xmlwriter" "--without-sqlite" "--without-wddx" "--enable-debug-pack" "--enable-cli-win32" "--enable-pdo" "--with-openssl" "--with-php-build" "--with-libxml" "--with-sqlite3" "--with-pdo-sqlite"
Server API CGI/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File C:\Program Files (x86)\Zend\ZendServer\etc\php.ini
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
PHP API 20090626
PHP Extension 20090626
Zend Extension 220090626
Zend Extension Build API220090626,NTS,VC9
PHP Extension Build API20090626,NTS,VC9
Debug Build no
Thread Safety disabled
Zend Memory Manager enabled
Zend Multibyte Support disabled
IPv6 Support disabled
Registered PHP Streams https, ftps, php, file, glob, data, http, ftp, zip, compress.zlib, compress.bzip2, phar
Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tls
Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*, bzip2.*, mcrypt.*, mdecrypt.*
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
with Zend Extension Manager v5.1, Copyright (c) 2003-2010, by Zend Technologies
- with Zend Data Cache v4.0, Copyright (c) 2004-2010, by Zend Technologies [loaded] [licensed] [enabled]
- with Zend Job Queue v4.0, Copyright (c) 2004-2010, by Zend Technologies [loaded] [not licensed] [disabled]
- with Zend Session Clustering v4.0, Copyright (c) 2004-2010, by Zend Technologies [loaded] [not licensed] [disabled]
- with Zend Utils v1.0, Copyright (c) 2004-2010, by Zend Technologies [loaded] [licensed] [enabled]
- with Zend Optimizer+ v4.1, Copyright (c) 1999-2010, by Zend Technologies [loaded] [licensed] [enabled]
- with Zend Code Tracing v1.0, Copyright (c) 2009-2010, by Zend Technologies [loaded] [not licensed] [disabled]
- without debugger [not loaded]
- with Zend Cluster Utils v1.0.0, Copyright (c) 2004-2010, by Zend Technologies [loaded] [licensed] [enabled]
- with Zend Page Cache v4.0, Copyright (c) 2004-2010, by Zend Technologies [loaded] [not licensed] [disabled]
- with Zend Monitor UI extension v4.1, Copyright (c) 2004-2010, by Zend Technologies [loaded] [licensed] [enabled]
|
I will try to run it on a linux based development server and see if it is my computer or not.
Thanks a lot for your time and interest in topic U.Tews, if I have any findings about the issue, I will inform. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Nov 12, 2012 1:30 am Post subject: |
|
|
btw. do you use the latest version of Smarty 3? |
|
Back to top |
|
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Mon Nov 12, 2012 3:26 am Post subject: |
|
|
As far as I am aware of, 3.1.12,
Quote: |
* SVN: $Id: Smarty.class.php 4658 2012-09-11 16:23:30Z <snipped email> $
const SMARTY_VERSION = 'Smarty-3.1.12';
|
|
|
Back to top |
|
cbj4074 Smarty Regular
Joined: 10 Nov 2011 Posts: 49
|
Posted: Mon Nov 12, 2012 8:26 pm Post subject: |
|
|
If you're tired of guessing as to the source of the memory consumption, install xdebug: http://xdebug.org/
DISCLAIMER: Never install xdebug on a production system; it is intended for use in local and development environments only. Installing xdebug on a production system will degrade its performance considerably and may expose sensitive server configuration or application details.
After installing xdebug, have a look at the author's memory usage article: http://derickrethans.nl/xdebug-and-tracing-memory-usage.html
If you're still stumped, let us know. |
|
Back to top |
|
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Tue Nov 13, 2012 5:18 am Post subject: |
|
|
As I pasted out phpinfo, I already had Xdebug before but unable to figure out the memory leak so far.
Quote: |
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
|
Quote: |
Showing the 20 most costly calls sorted by 'memory-own'.
Inclusive Own
function #calls time memory time memory
-------------------------------------------------------------------------------------------------
preg_match 1409 0.8101 5858624 0.8101 5858624
smartyAutoload 5 0.0975 1004936 0.0894 1004552
Smarty_Internal_Templateparser->yy_shift 1318 1.5746 516768 0.8818 453440
ob_start 9 0.0047 369784 0.0047 369784
array_filter 1190 0.6706 222472 0.6706 222472
require_once 18 0.1339 232984 0.0546 119616
Smarty_Internal_Templateparser->yy_is_expected_token 3265 14.8134 104480 4.0484 104480
|
somehow it shows up ~1400 preg_match calls, i have no idea if that is normal or not.
ignore the time that script took to execute, it was because of debugging and tracing was turned on.
also I set force_compile = 1 and caching = 0 for peak results.
http://pastebin.com/Rts3LhAB
cachegrind.out.zip -> http://www.mediafire.com/?cek51j842clyhla
trace.zip -> http://www.mediafire.com/?s4p9162ohoh6327
Edit:
also adding the results with force_compile = 0 and caching = 1
Quote: |
Showing the 20 most costly calls sorted by 'memory-own'.
Inclusive Own
function #calls time memory time memory
------------------------------------------------------------------------------------
require 1 0.0470 94120 0.0318 93480
require_once 9 0.1030 190224 0.0291 92976
ob_start 2 0.0010 82336 0.0010 82336
mysql_fetch_array 88 0.0491 46936 0.0491 46936
myautoload 6 0.1000 223528 0.0270 36936
mysql_query 12 0.0855 21536 0.0855 21536
preg_replace 5 0.0035 17224 0.0035 17224
include 4 0.0857 43672 0.0124 16336
Smarty_Internal_Data->assign 22 0.0415 9336 0.0183 7928
|
http://pastebin.com/ipzckUhE
cachegrind.out01.zip -> http://www.mediafire.com/?2vq9af8rqmbn1qu
trace.zip -> http://www.mediafire.com/?l1dyxedejvesxef |
|
Back to top |
|
cbj4074 Smarty Regular
Joined: 10 Nov 2011 Posts: 49
|
Posted: Tue Nov 13, 2012 5:22 pm Post subject: |
|
|
Quote: |
somehow it shows up ~1400 preg_match calls, i have no idea if that is normal or not.
|
Are you sure that you didn't run the profiling script against a trace file that the profile script itself generated? All of those preg_match() calls seem to be from the profiling script, not your application.
When I run the profiling script against the trace that you posted at http://www.mediafire.com/?s4p9162ohoh6327 , I see the following output:
Code: |
Showing the 20 most costly calls sorted by 'memory-own'.
Inclusive Own
function #calls time memory time memory
------------------------------------------------------------------------------------
require 1 0.0470 94120 0.0318 93480
require_once 9 0.1030 190224 0.0291 92976
ob_start 2 0.0010 82336 0.0010 82336
mysql_fetch_array 88 0.0491 46936 0.0491 46936
myautoload 6 0.1000 223528 0.0270 36936
mysql_query 12 0.0855 21536 0.0855 21536
preg_replace 5 0.0035 17224 0.0035 17224
include 4 0.0857 43672 0.0124 16336
Smarty_Internal_Data->assign 22 0.0415 9336 0.0183 7928
mysql_connect 1 0.0262 5888 0.0262 5888
array_merge 2 0.0011 4528 0.0011 4528
core->__construct 1 0.4469 303952 0.0134 4416
page->doAssignments 1 0.0460 12192 0.0035 3704
sql_db->sql_fetchrow 88 0.1105 50088 0.0614 3152
page->__construct 1 0.0311 8408 0.0015 1712
Smarty_Variable->__construct 24 0.0127 1600 0.0127 1600
Smarty->createTemplate 1 0.0021 1816 0.0010 1576
core->getPageList 1 0.0311 13856 0.0026 1504
session->pagestart 1 0.0356 12392 0.0021 1464
preg_match_all 1 0.0006 1152 0.0006 1152
|
This looks pretty normal.
Here's a comparable trace from one of my applications that makes heavy use of Smarty:
Code: |
Showing the 20 most costly calls sorted by 'memory-own'.
Inclusive Own
function #calls time memory time memory
--------------------------------------------------------------------------------------
ApplicationBase->loadClass 13 0.0700 1322080 0.0238 832312
require 19 0.0360 490320 0.0158 487936
DataHierarchy->__construct 1 0.1160 1230328 0.0093 476584
include_once 11 0.0314 428720 0.0109 427184
MDB2->loadClass 1 0.0051 247096 0.0041 246888
DB_NestedSet->factory 1 0.0945 749088 0.0020 48360
ApplicationBase->__construct 1 0.1904 1378512 0.0128 47400
MDB2_Driver_Common->__destruct 1 0.0015 -5776 -0.0005 19520
ob_start 1 0.0003 16496 0.0003 16496
mysqli_result->free 2 0.1803 16352 0.1133 11808
Db::getNumRows 3 0.0965 9864 0.0965 9864
MDB2->factory 1 0.0240 262560 0.0008 9504
array_merge 4 0.0044 8320 0.0044 8320
call_user_func_array 1 0.0025 6504 0.0025 6504
mysqli->mysqli 1 0.0022 6008 0.0022 6008
require_once 4 0.0320 6176 0.0079 5712
str_split 6 0.0015 5696 0.0015 5696
ApplicationBase->loadSmarty 1 0.0683 19448 0.0020 5528
Smarty_Internal_Data->assign 22 0.0232 4768 0.0101 5472
method_exists 2 0.0056 5224 0.0056 5224
|
The second bit of profile output looks correct, in as much as you ran the profile script against a trace file that did in fact come from your application. Again, these values look normal, and I see no indication that the script is consuming some ridiculous amount of memory, such as 512MB.
If the memory exhausting problem happens only intermittently, perhaps you should leave tracing enabled and try refreshing your application until the problem occurs, and then analyze the appropriate trace file. I would expect the .xt file to be much, much larger/longer when the problem occurs. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Nov 13, 2012 6:26 pm Post subject: |
|
|
Quote: | somehow it shows up ~1400 preg_match calls, i have no idea if that is normal or not. |
The high number of preg_match calls are from Smarty's lexer as you forced recompilation of all templates by force_compile = true; (there is one call for each token).
But this does not explain the memory consumption.
You provide a zip of all template sources? You can PM in case you don't want to make it public. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|