Solved

PHPMailer: Cannot override final method Exception::__clone()

Posted on 2013-12-13
11
830 Views
Last Modified: 2013-12-23
Using latest version of PHPMailer (5.2.7)
PHP v5.3.10
jQuery 1.8.2
jQuery Mobile 1.3.0

I am writing a Web program in PHP that sends a text message to a mobile device. The initial message may be instigated from a normal Web page or a jQuery Mobile page. After receiving the message, the recipient selects a link that goes to a Mobile page, and pulls up the record saved from the original form that instigated the initial message. The recipient then responds through a radio button selection, which saves to the database and sends a text message to the originators cell phone. That person then responds back.

Intermittently, when that response is made, PHPMailer errors out with the following message:
<b>Fatal error</b>:  Cannot override final method Exception::__clone() in <b>/home/best/public_html/m/PHPMailer/class.phpmailer.php</b> on line <b>3297</b>

At 3297 in PHPMailer is the following (starting at 3292):
/**
 * PHPMailer exception handler
 * @package PHPMailer
 */
class phpmailerException extends Exception
{
    /**
     * Prettify error message output
     * @return string
     */
    public function errorMessage()
    {
        $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
        return $errorMsg;
    }
}

Open in new window

It seems that something is held in a cache somewhere (or  ???) because once this error occurs, it will continue to fail whenever another attempt is made, even when the process is started from the beginning. It seems like this times out after a while.

In testing, I have gone back and forth as much as 20 times with no errors. At other times it errors on the first response back to the original recipient.

I am totally at a loss.
0
Comment
Question by:RationalRabbit
  • 6
  • 5
11 Comments
 
LVL 25

Expert Comment

by:Squinky
Comment Utility
It could be that you are including the file twice. Are you using the autoloader?
0
 

Author Comment

by:RationalRabbit
Comment Utility
No, I'm not using the autoloader. Should I be?
I'm using require_once, and there is no loop or anything that would load it again, anyway.
I'm using the same script on several other sites for e-mail and have never had any problems, but I am wondering, with this back and forth communication if something isn't being held in a browser or server cache.
0
 
LVL 25

Expert Comment

by:Squinky
Comment Utility
I do recommend using the auto loader. There are several reports of this error on stackoverflow, and in those cases it was caused by multiple loads. It might be a good idea to break out the exception class into a separate file. Also to check for multiple loads, stick an echo/log or breakpoint in it so you can see if it's happening.
0
 

Author Comment

by:RationalRabbit
Comment Utility
Autoloader is now active, and I followed your advice on checking for multiple loads. I do not believe there is anything in the code creating multiple loads. However, that is, of course, the problem. I've not found any reference to any other reason that error would be triggered.

It appears the reason for the intermittent error is that the class is held in server memory somewhere and I'm not very educated on how classes are handled in that manner.

My conclusion is based on the fact that, when the error occurs, I cannot attempt to send again without receiving the same error - not from the original browser or any other - until a few minutes have passed. I don't know exactly what that period is, but it is shorter than a normal session timeout.  During this period, I have tried to send from two desktop browsers as well as my cell phone. All failed.  Tested several times.

What makes this really frustrating is that there seems to be no consistency. I've been very careful to be consistent in the data entry and sending, but after several successes it will suddenly error.
0
 
LVL 25

Expert Comment

by:Squinky
Comment Utility
How are you spotting the multiple loads? If you're just doing an echo, try doing a stack trace (var_dump(debug_backtrace());) instead so you can see how it got there.
Another possibility can be if you have the same file in two places in your path, it may be loading the same class from two different places. I'd normally expect that to throw a 'class already defined' or something, but it might just be causing this too.
Another possibility could be your opcode cache (Zend, APC, xcache etc) doing something odd; try turning it off.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:RationalRabbit
Comment Utility
PHPMailer has an smtp class which had a timeout set at 300 seconds (5 Minutes!) I changed this to 50 seconds, and I haven't been able to recreate the problem in 45 minutes of sending messages back and forth.

I wouldn't consider this closed, because that may not have been the problem at all - it is so intermittent.  Do you think its possible this was holding up the closing of the PHPMailer class?

Concentrating on other things now, but tomorrow will set the smtp timeout back, add the backtrace var dump and if it does it again see what I can see. Or - maybe it will do it again before then.

By the way, thanks for informing me of the debug_backtrace! Very handy.
0
 
LVL 25

Accepted Solution

by:
Squinky earned 500 total points
Comment Utility
This is an inherent problem with using SMTP interactively (e.g. on a page submission) - it's really not a good thing to do. The SMTP RFC2822 says that the timeout should be 300 sec, so that's what it is by default. If you run a local MTA (I'd recommend postfix) and use 'sendmail' or 'mail' mailer types in PHPMailer, this potential delay can't happen. Direct SMTP is very much a compromise, and should be avoided if at all possible. If you are forced to use SMTP, try to use a nearby mail server (e.g. your ISPs one) rather than trying to send directly to recipient's servers. Even if mail servers respond quickly, if you're sending to big ISPs (particularly yahoo), in anything but trivial quantities, you're very likely to get deferrals, and they are essentially impossible to handle interactively.
0
 

Author Comment

by:RationalRabbit
Comment Utility
Seems that the SMTP timeout was the problem. For this purpose, I really don't need to use it, so I guess I'll switch.

Thanks for your input.
0
 

Author Comment

by:RationalRabbit
Comment Utility
I'm not sure what the protocols are here - whether I now have to open a new question - but, unfortunately, it seems this did not solve the problem. It has cropped up again - this time more persistent than ever. I am not using SMTP.
0
 
LVL 25

Expert Comment

by:Squinky
Comment Utility
Have you tried moving the exception class into a separate file? If you name it according to the pattern in the autoloader it should 'just work'.
0
 

Author Comment

by:RationalRabbit
Comment Utility
I just abandoned PHPMailer and installed Swift. Seems to be working fine.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Email attacks are the most efficient and effective way for cyber criminals and hackers to compromise a computer or network. We often find our-self second guessing the authenticity of an email message, for such instances we can follow practical princ…
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now