Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1043
  • Last Modified:

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

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
RationalRabbit
Asked:
RationalRabbit
  • 6
  • 5
1 Solution
 
Marcus BointonCommented:
It could be that you are including the file twice. Are you using the autoloader?
0
 
RationalRabbitAuthor Commented:
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
 
Marcus BointonCommented:
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
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
RationalRabbitAuthor Commented:
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
 
Marcus BointonCommented:
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
 
RationalRabbitAuthor Commented:
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
 
Marcus BointonCommented:
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
 
RationalRabbitAuthor Commented:
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
 
RationalRabbitAuthor Commented:
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
 
Marcus BointonCommented:
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
 
RationalRabbitAuthor Commented:
I just abandoned PHPMailer and installed Swift. Seems to be working fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now