Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-13
11
Medium Priority
?
922 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 39718354
It could be that you are including the file twice. Are you using the autoloader?
0
 
LVL 1

Author Comment

by:RationalRabbit
ID: 39718427
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:Marcus Bointon
ID: 39718769
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:RationalRabbit
ID: 39720289
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:Marcus Bointon
ID: 39720465
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
 
LVL 1

Author Comment

by:RationalRabbit
ID: 39720570
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:
Marcus Bointon earned 1500 total points
ID: 39720923
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
 
LVL 1

Author Comment

by:RationalRabbit
ID: 39727606
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
 
LVL 1

Author Comment

by:RationalRabbit
ID: 39735395
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:Marcus Bointon
ID: 39735632
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
 
LVL 1

Author Comment

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

Featured Post

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you irritated by repeating emails issue in Microsoft Outlook 2016 after recent update ?  Lets’ see how to resolve and prevent duplicate emails in the Outlook 2016 using some simple techniques.
Read this checklist to learn more about the 15 things you should never include in an email signature.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 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