News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

PHP Fatal error: Cannot redeclare template_quotefast

Started by Black Tiger, December 09, 2014, 07:30:15 PM

Previous topic - Next topic

Black Tiger

It's not a big issue, but it's creating an error_log and I wonder what's the cause. This week it happened 3 times and this is the complete error_log:
[02-Dec-2014 10:42:01 Europe/Amsterdam] PHP Fatal error:  Cannot redeclare template_quotefast() (previously declared in /home/customer/public_html/forum/Themes/default/Xml.template.php:25) in /home/customer/public_html/forum/Themes/default/Post.template.php on line 1001
[05-Dec-2014 02:22:28 Europe/Amsterdam] PHP Fatal error:  Cannot redeclare template_quotefast() (previously declared in /home/customer/public_html/forum/Themes/default/Xml.template.php:25) in /home/customer/public_html/forum/Themes/default/Post.template.php on line 1001
[06-Dec-2014 08:33:18 Europe/Amsterdam] PHP Fatal error:  Cannot redeclare template_quotefast() (previously declared in /home/customer/public_html/forum/Themes/default/Xml.template.php:25) in /home/customer/public_html/forum/Themes/default/Post.template.php on line 1001


As you can see it's always the same files.
So I checked and line 25 in Xml.template.php states:
        global $context, $settings, $options, $txt;

Line 1001 in Post.template.php reads:
}

As far as I know, these files are both original files, they both dated June 6Th 2011 and I'm running SMF 2.0.9.
Mods installed:
1.    My Posts SMF2    1.2
2.    Redirection Topics    1.0.3
3.    SimplePortal    2.3.6
4.    Remove "Last edit" mod    0.2.5
5.    Downloads System    2.0
6.    Contact Page

As said, it's not a very big problem, just wondering why this is happening with default files (as far as I know).
Greetings, Black Tiger

Arantor

So what URL is being accessed when that error occurs?

Something is doing the posting - while the XML template is loaded, which is what causes the problem. But nothing comes to mind as to why the XML template should be loaded in that situation.

Bob Perry of Web Presence Consulting

yes, it is so a "big issue"... sort of, your users will not be able to use certain areas of your system until this is fixed, yes,  a link to your site please?

Best Regards,
Bob Perry



"The world is moving so fast these days that the man who says it can't be done is generally interrupted by someone doing it." Elbert Hubbard

Black Tiger

@Bob Perry: Sometimes I wonder if people here even do read what is written. I clearly stated =twice= that it's not a big issue, just something which makes me curious. So please explain why you make a doubtful comment about some big issue? Link is below.

@Arantor: I don't have a clue on that, sorry. I just find this in the forums error_log now and then.
http://www.satellitefun.org/forum is the url of the forums, but I don't know how to find out exactly how to reproduce the problem.
Greetings, Black Tiger

Arantor

Presumably something in the Apache access log, at the same timestamp, with status 500, to indicate the URL?

Black Tiger

I could use that, but the problem is that there was a log rotation on the 8Th so unfortunately I could'nt look it up.
But since it's not an issue, I can easily wait until it happens again in the forum log and look it up in the apache logs at that time. I'll keep you informed!
Greetings, Black Tiger

Black Tiger

Oke I managed to get the cause of the error notice. Looks like it has to do something with previews:
This is from the apache logfile:

First time it happened today at 18:10 hours:
[14/Dec/2014:18:10:56 +0100] POST /forum/index.php?action=post2;board=75;preview;xml HTTP/1.1" 500 26 "http://www.satellitefun.org/forum/index.php?action=post;board=75.0"

The second time with a slight difference at 18:11 hours:
[14/Dec/2014:18:11:38 +0100] POST /forum/index.php?action=post2;board=75;preview;xml HTTP/1.1" 500 26 "http://www.satellitefun.org/forum/index.php?action=post2;start=0;board=75"

I just checked and it's just a normal post, made by a new user. But it's also the only preview I can find in the log of today.
Greetings, Black Tiger

Arantor

Hmm, the URL's right and the path seems normal enough in terms of what it loads.

What mods are installed?

Black Tiger

These are the mods currently installed.
1.    My Posts SMF2    1.2
2.    Redirection Topics    1.0.3
3.    SimplePortal    2.3.6
4.    Optimus Brave    1.8.7
5.    Tapatalk SMF 2.0 Plugin
6.    Remove "Last edit" mod
7.    Global Headers Footers
8.    Birthday On Register
9.    Downloads System
10.    Contact Page

However, when this error occured for the first time it was only these mods installed:
1.    My Posts SMF2    1.2
3.    SimplePortal    2.3.6
6.    Remove "Last edit" mod
9.    Downloads System
10.    Contact Page
Greetings, Black Tiger

Black Tiger

Oh I've just seen I posted the mods already in my first question. ;)
Greetings, Black Tiger

Arantor

Hmmm, curious. Nothing on there except maybe SimplePortal could cause this and even then it still shouldn't :(

Black Tiger

It shouldn't indeed, but it does, however luckily only a very few times and it does no harm, so it's still not very important.

In that case I might go over there and ask if they have a clue.
Thanks!
Greetings, Black Tiger

David July

I am not running SimplePortal yet recently discovered the same "Cannot redeclare template_quotefast" error_log entries as Black Tiger reported, along with the corresponding "POST /index.php?action=post2;board=4;preview;xml HTTP/1.1" entry in the Apache access log.  The only mod installed is Menu Editor Lite (1.0.5).

The two most recent instances of the error were on 19 December 2014.  I determined that they both occurred for the same user, first when they started a new thread and second during their third reply in it.  That same user's other two replies as well as two replies by another user did not generate the error.

I have emailed the user to see if they experienced any usual behavior during this instance.  I anticipate they will report nothing out of the ordinary however, because I found an error entry that corresponds to a post I made and nothing strange happened then.

Given that nothing seems amiss with the operation of the forum, I appear to be in a similar situation as Black Tiger—curious but not particularly concerned.  I wanted to provide these details in case it helps.  Thanks.

Black Tiger

Thank you for sharing. However I can state the SimplePortal can not be the cause, because I'm having the same issue on another forum on the same server, which does not have Simpleportal installed.
Maybe this way we can narrow the problem somehow.
Greetings, Black Tiger

fun4us

Hello,
i have nearly the same issue here.

QuotePHP Fatal error:  Cannot redeclare template_quotefast() (previously declared in /data/www/mineralienatlas/htdocs/forum/Sources/Load.php(2172) : eval()'d code:25) in /.../forum/Sources/Load.php(2172) : eval()'d code on line 1001

It always happens while opening a message preview. Nothing bad seems to happen except the log entry.
Only mod highslide image viewer. SMF 2.0.9.

Any reason while it is marked to be closed without solution?
Cheers Stefan

fun4us

Post.template.php

Add the red lines and no more error.

if (!function_exists('template_quotefast')) {
function template_quotefast()
{
global $context, $settings, $options, $txt;

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<title>', $txt['retrieving_quote'], '</title>
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
</head>
<body>
', $txt['retrieving_quote'], '
<div id="temporary_posting_area" style="display: none;"></div>
<script type="text/javascript"><!-- // --><![CDATA[';

if ($context['close_window'])
echo '
window.close();';
else
{
// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
echo '
var quote = \'', $context['quote']['text'], '\';
var stage = \'createElement\' in document ? document.createElement("DIV") : document.getElementById("temporary_posting_area");

if (\'DOMParser\' in window && !(\'opera\' in window))
{
var xmldoc = new DOMParser().parseFromString("<temp>" + \'', $context['quote']['mozilla'], '\'.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_") + "</temp>", "text/xml");
quote = xmldoc.childNodes[0].textContent.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
}
else if (\'innerText\' in stage)
{
setInnerHTML(stage, quote.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
quote = stage.innerText.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
}

if (\'opera\' in window)
quote = quote.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, \'"\').replace(/&amp;/g, "&");

window.opener.oEditorHandle_', $context['post_box_name'], '.InsertText(quote);

window.focus();
setTimeout("window.close();", 400);';
}
echo '
// ]]></script>
</body>
</html>';
}

}

Black Tiger

I don't know, I did not tick it solved and I was not notified that it would be set to solved.
If a moderator has a reason to put it to solved I'm sure they will tell us why. In the meantime I will put it to unsolved again, especially since more more forums having this issue.

Fun4us: Exactly where do I put that red line?

Next to that... if this is a solution, should this be fixed by the team in the core files?
Greetings, Black Tiger

fun4us

Hi,
in front and after the code in the code box. You will find the file Post.template.php in the Themes/default folder. There you will find the code from the box inside.

find:
function template_quotefast()
{
global $context, $settings, $options, $txt;

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<title>', $txt['retrieving_quote'], '</title>
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
</head>
<body>
', $txt['retrieving_quote'], '
<div id="temporary_posting_area" style="display: none;"></div>
<script type="text/javascript"><!-- // --><![CDATA[';

if ($context['close_window'])
echo '
window.close();';
else
{
// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
echo '
var quote = \'', $context['quote']['text'], '\';
var stage = \'createElement\' in document ? document.createElement("DIV") : document.getElementById("temporary_posting_area");

if (\'DOMParser\' in window && !(\'opera\' in window))
{
var xmldoc = new DOMParser().parseFromString("<temp>" + \'', $context['quote']['mozilla'], '\'.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_") + "</temp>", "text/xml");
quote = xmldoc.childNodes[0].textContent.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
}
else if (\'innerText\' in stage)
{
setInnerHTML(stage, quote.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
quote = stage.innerText.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
}

if (\'opera\' in window)
quote = quote.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, \'"\').replace(/&amp;/g, "&");

window.opener.oEditorHandle_', $context['post_box_name'], '.InsertText(quote);

window.focus();
setTimeout("window.close();", 400);';
}
echo '
// ]]></script>
</body>
</html>';
}



and replace

if (!function_exists('template_quotefast')) {
function template_quotefast()
{
global $context, $settings, $options, $txt;

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<title>', $txt['retrieving_quote'], '</title>
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js"></script>
</head>
<body>
', $txt['retrieving_quote'], '
<div id="temporary_posting_area" style="display: none;"></div>
<script type="text/javascript"><!-- // --><![CDATA[';

if ($context['close_window'])
echo '
window.close();';
else
{
// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
echo '
var quote = \'', $context['quote']['text'], '\';
var stage = \'createElement\' in document ? document.createElement("DIV") : document.getElementById("temporary_posting_area");

if (\'DOMParser\' in window && !(\'opera\' in window))
{
var xmldoc = new DOMParser().parseFromString("<temp>" + \'', $context['quote']['mozilla'], '\'.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_") + "</temp>", "text/xml");
quote = xmldoc.childNodes[0].textContent.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
}
else if (\'innerText\' in stage)
{
setInnerHTML(stage, quote.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
quote = stage.innerText.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
}

if (\'opera\' in window)
quote = quote.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, \'"\').replace(/&amp;/g, "&");

window.opener.oEditorHandle_', $context['post_box_name'], '.InsertText(quote);

window.focus();
setTimeout("window.close();", 400);';
}
echo '
// ]]></script>
</body>
</html>';
}
}



This is a workaround to check if the function is loaded before and if it will not load again. So no more error. The fix whould be to find where the function is loaded twice and to remove this.

But both will work.
Cheers

Black Tiger

Oke thank you, this will bring some peace and quiet in the log file.

However I will leave this topic open for the moment (not solved), because it happens on forums with different mods. Maybe the specialist can have a clue on where it could be loaded twice.
Maybe this way it can really be fixed instead of a workaround.
Greetings, Black Tiger

Kindred

but it does not happen on a standard installation (and I have also installed over 200 mods on a system and never seen the issue)

So, it would seem to be some specific combination of mods...   but unlikely to be updated in the core, since it never happens to a clean installation.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Black Tiger

I was thinking of that too Kindred, until the other users came to post here.

From David July:
QuoteThe only mod installed is Menu Editor Lite (1.0.5).
We don't have that on any of both forums.

From Fun4us:
QuoteOnly mod highslide image viewer. SMF 2.0.9.
We don't have that mod on any of our forums either.

And if I understand them correctly, they both don't have any of the mods we are using on the forums or even any other mod at all, but they are are having the same php error.

Ofcourse I believe you as you say that it does not happen on a standard installation.
But since it also does not seem to be a specific combination of mods, as to the statements of David and Fun4us.... could it be some issue caused by the package manager?
Greetings, Black Tiger

Black Tiger

I'll mark it as solved since we got a workaround now (thank you fun4us!) and it's not a big issue and not a default installation thing.

If somebody finds the exact cause in the near future, they can always put a reply here.
Greetings, Black Tiger

Arantor

I will have to investigate this, I'm seeing it on my latest website, which has no mods in common with any of the mods outlined previously.

Black Tiger

If you got time that would be nice Arantor. No hurry though, I'm already happy with the workaround, the rest is just curiosity. ;)
Greetings, Black Tiger

fun4us

This is no problem with mods. i have one more, but less frequented smf 2.0.9 installation and it has the same problem.

Open a new message und press preview. Thats all to see the error.

Kindred

I am not saying that you are definitely wrong... And yet, despite running SMF for almost 10 years, and running 2.0.9 since before it was officially release, I have never seen that error on any of my 4 sites...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Black Tiger

Greetings, Black Tiger

Arantor

I can reproduce it but only on an environment without XDebug installed, which is weird in itself.

Kindred

and strangely enough... I can not reproduce it at all...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Black Tiger

Very odd... it gets more curious while investigating it. LoL. :D
Greetings, Black Tiger

David July

I applied the fun4us fix (thanks Stefan!) to my custom theme's Post.template.php yesterday.  Based on my tests then and again today, it appears to be working so far.  However as the issue was occurring intermittently, I will need to wait and see what happens after some regular use.  I will report back if I learn anything new.

Kindred

Well, of course that works....however, it should not be needed....   As I noted, without the "fix" I can't even recreate the issue on my own system.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

DarkAngel612

I have noticed this off and on, just as mysteriously as it starts it stops. tonight I find a very filled log file (server side) that it is from Dec. 29 until now. I have applied the fix and below in the image is all the mods we have installed. will check other forums to see if it is the same there too (most of the mods are there too) and will apply the "fix" too.
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.0+ with various mods and TinyPortal

Arantor

The fix doesn't magically make it fixed, it just hides the error - and it may have other unintended side effects, hard to know.

fun4us

QuoteThe fix doesn't magically make it fixed, it just hides the error - and it may have other unintended side effects, hard to know.

Sorry you are wrong. It fixes the error and stops loading twice the same function. It does not only hide the error. But the best solution is to find why the function is loaded twice and to stop this. The result will be the same.

Kindred

No, Arantor is correct...   It just hides the error by preventing the double load... However, That code should not be needed.. Most especially since I can still not reproduce it and have never seen the error on any of the 6 sites that I have run

Hiding the error with code like that does not solve the actaully problem of WHY some people are getting a double load while others do not
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

fun4us

@function whould be a hide   ;) but lets find the place where it is loaded twice to stop our messages without any helpful content. Feel free to remove the last massages.

Kindred

to be a bit pedantic... :D

@... would SUPPRESS the error...
the code as suggested HIDES it, by making it impossible to see it and debug it further. :)

anyway...   as I said, it is very difficult to debug this, since I can't even recreate it.... :(
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor


hushpiper

Poking my head in to note that I'm also seeing this error on my forum, after moving it to a new server, upgrading it to 2.0.9 and installing a few mods (Expandable Spoiler BBCode v1.7 and Yet Another Youtube BBCode v2.1). Redacted error_logs:

[25-Apr-2015 12:16:05 America/New_York] PHP Fatal error:  Cannot redeclare template_quotefast() (previously declared in /[redacted]/Sources/Load.php(2151) : eval()'d code:25) in /[redacted]/Sources/Load.php(2151) : eval()'d code on line 1001

And Apache logs:

[IP redacted] - - [25/Apr/2015:10:16:05 -0600] "POST /index.php?action=post2;board=1;preview;xml HTTP/1.1" 500 2133 "https://ssssforum.com/index.php?action=post2;start=4635;board=1" "Mozilla/5.0 (Windows NT 6.3; WOW64)

The issue is reproducible: it happens every time someone tries to preview a post. The preview does happen, but it is noticeably slow. I haven't done the fix fun4us suggested because I want to keep an eye on it. I'm going to investigate the possibility that this might've happened due to some mods getting installed twice by accident, but any suggestions as to what might be causing it would be appreciated.

charpress

As of yesterday I have a white screen dead forum.

Looking at the error logs, I see the error referenced here starting on occasion going way back. But in the last day the error appears a dozen times.

I don't know yet whether the error is causing the white screen or maybe the other way around. I'm just starting to look into this.

Steve

Not quite sure why you posted in this thread. You should start a new one as this has been marked solved and your problem looks unrelated to the OP's problem.
DO NOT pm me for support!

whoey

Ironically this quotefast fix worked for us just now on 2.0.19, suddenly we had the same slow post lag, and the comment on #15/17 fixed it.

Advertisement: