Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Endless loop while trying to compile a template
Goto page Previous  1, 2
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Thu Oct 06, 2011 11:04 am    Post subject: Reply with quote

Not that I'm aware of.

The page that shows the giant output is the list of pages of my CMS. So the array I assign is the array of Page objects of my CMS. Page objects have numerous properties, some of which containing objects themselves. But I'm pretty sure that none of the properties contains a Smarty object.

Why do you think it got nothing to do with the compiling? Once it is compiled (by removing the assignment of the array) everything is back to normal and I'm even able to assign the array again...
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Thu Oct 06, 2011 12:13 pm    Post subject: Reply with quote

I created a small test script to help identify your problem. Except for the obvious "duplicate" I don't get any memory errors, though. https://gist.github.com/1267257 please take this script and modify it (step by step) to your setup and usage.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Thu Oct 06, 2011 12:16 pm    Post subject: Reply with quote

Alright, thanks, will do Smile

Might take a while though. I'll get back to you asap. Thanks!! Smile
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Thu Oct 06, 2011 12:17 pm    Post subject: Reply with quote

Mastershrimp wrote:
The page that shows the giant output is the list of pages of my CMS. So the array I assign is the array of Page objects of my CMS. Page objects have numerous properties, some of which containing objects themselves. But I'm pretty sure that none of the properties contains a Smarty object.


then maybe you're just wrangling too much data for your php environment to handle?

Mastershrimp wrote:
Why do you think it got nothing to do with the compiling? Once it is compiled (by removing the assignment of the array) everything is back to normal and I'm even able to assign the array again...


The compiler doesn't care about any data you've assigned (unless you created compiler plugins that use assigned data…). Whatever kills the script is most likely happening while executing the compiled template.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Thu Oct 06, 2011 12:19 pm    Post subject: Reply with quote

No, I dont have any custom compiler plugins.

Well, sure, it's a lot of data. But PHP usually handles it just fine. As I said, everything works fine once smarty was able to compile the templates. So the general load cannot be the problem here.

And if it was, Smarty 3.1 would be way more inefficient than 3.0 - I dont think so Wink
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Thu Oct 06, 2011 12:30 pm    Post subject: Reply with quote

from the script you can gather how to calculate how much memory you've used by assigning your data. If that doesn't leave enough space for the compiler, sure, the compiler will be the "cause" of the memory allocation error.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Thu Oct 06, 2011 12:40 pm    Post subject: Reply with quote

And then it would print the whole Smarty object? Mh....

Right now I think some odd server configuration or PHP bug causes Smarty to get printed, which is a huge operation due to the big array, so in the end the script crashes with a memory limit exceed.

As I said, Smarty 3.0 was fine. The amount of data didnt change since then. And I'm running the affected template on even bigger systems with 2x the data volume - and no problem.

There's something incompatible with 3.1 and that particular server configuration.....I'll have to fix something else first, then i'll dive right into the bug-fixing process Wink Hope to be able to give you the first results soon. Beginning of next week tops.
Back to top
View user's profile Send private message
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Thu Oct 20, 2011 10:45 am    Post subject: Reply with quote

Sorry for being quiet in the past days. Had to work on some other stuff Wink But now I gave it another try - especially since in the meantime you guys released a bunch of updates Wink

First of all: The problem still exists in 3.1.4.

So I decided to go the tedious but straight-forward way and debugged Smarty manually on the server. I added "echo 'test'" at several positions in your code to see which function is the last one called before the giant output. This is most likely the one causing the output.

In the end I found the culprit. Have a look at smarty_internal_write_file.php line 49. It says:
Code:
// remove original file
unlink($_filepath);


And for some reason unlink() goes completely berserk and produces the giant output. So I tried
Code:
// remove original file
@unlink($_filepath);

and voila, it works perfectly fine. A lot faster than 3.0 (at least it feels so) and the memory usage is also just fine (peak: 9MB according to PHP)

I briefly tried to find a bug report related to this issue, but couldnt find one. So I really dont know why and how the problem occurs. Maybe it's a process thing - i.e. one PHP process tries to delete the file while another has already deleted it (see Comment on php.net). No idea.


Nevertheless it seems to work now. Could you please add the "@" in front of unlink in the file mentioned above? That'd be great Smile

And maybe add the "@" in front of all unlink()s you use - just in case. I guess it doesnt harm and the comment on php.net also recommends it.


Thanks for the great help though! Really amazing how active the Smarty people are! Smile Keep up the good work!!


Edit: As far as I see all other occurrences of unlink already have a "@" Smile
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Thu Oct 20, 2011 10:53 am    Post subject: Reply with quote

we deliberately removed the @ from unlink() in Smarty_Internal_Write_File since we changed the error_reporting() in there. For some reason some debuggers don't like this much. If you're using custom error_handlers (that are not built according to spec) you'll see these errors, too. That's why we implemented Smarty::muteExpectedErrors().

I'm glad you found the cause, though.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Thu Oct 20, 2011 11:24 am    Post subject: Reply with quote

What do you mean "not built according to spec"? I indeed have my own error handler, but I tried to implement it the way PHP recommends it. It's been a while though....

Basically my method looks like this (I removed the part where I compose the actual message string):
Code:
function handlePHPError($errno, $errstr, $errfile="", $errline=null, $errcontext=array()) {
   // Only handle the error if the value of error_reporting() is not 0 (if it is, the method that triggered the error has been escaped with "@")
   if(error_reporting()>0) {
      $maxStrlenOfArg = 200; // This method prints the arguments of each method call. Since these arguments can be quite long, they are cut after X characters

      // --- TYPES OF ERRORS
      // See http://www.php.net/error-reporting
      $errorTypes = array();
      $errorTypes[1]      = "E_ERROR";
      $errorTypes[2]      = "E_WARNING";
      $errorTypes[4]      = "E_PARSE";
      $errorTypes[8]      = "E_NOTICE";
      $errorTypes[16]      = "E_CORE_ERROR";
      $errorTypes[32]      = "E_CORE_WARNING";
      $errorTypes[64]      = "E_COMPILE_ERROR";
      $errorTypes[128]   = "E_COMPILE_WARNING";
      $errorTypes[256]   = "E_USER_ERROR";
      $errorTypes[512]   = "E_USER_WARNING";
      $errorTypes[1024]   = "E_USER_NOTICE";
      $errorTypes[6143]   = "E_ALL";
      $errorTypes[2048]   = "E_STRICT";
      $errorTypes[4096]   = "E_RECOVERABLE_ERROR";
      $errorTypes[8192]   = "E_DEPRECATED";
      $errorTypes[16384]   = "E_USER_DEPRECATED";

      if(array_key_exists($errno, $errorTypes))
         $errorType = $errorTypes[$errno];
      else
         $errorType = "Error Type " . $errno;

      // --- ERROR MESSAGE
      $errMsg = "....compose error message...";


      // Print error message or throw exception respectively if allowed for the current error_reporting() level and terminate script
      if($errno<=E_ALL && $errno!=E_NOTICE && defined("E_DEPRECATED") && defined("E_USER_DEPRECATED") && $errno!=E_DEPRECATED && $errno!=E_USER_DEPRECATED) {
         if(!$errorCausedByException)
            throw new PhpErrorException($errMsg);
         else {
            // Log the message of this error
            if(Settings::ex("LOG_ERRORMSG_ON_SYS_ERROR") && Settings::val("LOG_ERRORMSG_ON_SYS_ERROR")==true) {
               Log::logSysError("[PHP error]\r\n" . $errMsg);
            }

            // Send email to developers
            if(Settings::ex("SEND_MAIL_ON_SYS_ERROR") && Settings::val("SEND_MAIL_ON_SYS_ERROR")==true) {
               Email::sendSysErrorMail($errMsg);
            }

            echo($errMsg);
            die();
         }
      }
   }
}



Anything I should add?

And: Since you deliberately removed the "@", does that mean that you wont add it again?
Back to top
View user's profile Send private message
Mastershrimp
Smarty Regular


Joined: 21 Dec 2009
Posts: 53

PostPosted: Thu Oct 20, 2011 12:15 pm    Post subject: Reply with quote

Alright, just saw the commit in the changelog! Thanks!! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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
Protected by Anti-Spam ACP