Website Spinning Out

Okay, this has me really freaked out… (But first some background!)

I do development on my MacBook and use MAMP, and I have been working on a decent sized website for over a year. I am currently in the final week of development, and the site looks and runs awesome, except for one strange thing… (But first, some more info!)

The way I wrote this website is that when there an error, the user is usually taken to an Error Page. (Probably “old-school” to a lot of you JavaScript freaks, but I like the approach myself.)

So, let’s say some hacker changed my $_POST array to some bogus value. Well, int he ELSE part of my If-Then-Else, I would simply redirect to my “errors.php” script, which would look through a CASE tree, and display the appropriate hard-coded error.

This has worked perfectly over the last year, and is usually lightning-quick!

Well, about 3 weeks ago, I broke down, and went back and replaced the mail( ) function with phpMailer because I have read it is more secure. So out of approximately 40 scripts, I had to add code for phpMailer in maybe 10. (It’s a little fuzzy now, but as I recall sometimes my e-mails were taking forever to go out.) But as of late, things seem to be okay.

And around the same time, I noticed that sometimes my Error Page was taking forever to load. (I mean like 3-5 minutes “forever”!!)

At first, I thought this was something that I screwed up with phpMailer, or maybe the fact that going from phpMailer to MAMP to e-mailing my Gmail account was somehow funky in “Dev”.

Sometimes it worked quickly, but some days it was mysteriously slow.

Well, after I updated all of these scripts, I noticed the same problem in place where phpMailer was NOT involved.

For example, my final script is an “Interest Survey” where a user goes in, checks/unchecks what they are interested in, and clicks save. This is a mundane, 500 line script. Well, when I added an new error-code as mentioned above, the Error Page didn’t load for a few minutes. (We are talking about PHP/MAMP having to process maybe 100-200 lines of code?!)

Obviously without seeing my entire code-base, this could be tricky for any of you to trouble-shoot.

(And since this is my client’s website, that ain’t gonna happen!!)

Still, I have to ask, [b]What in the hell is going on??"

And how in the hell do I figure out what is going on??[/b]

I pray to God this is just some crap related to MAMP or that when I don’t reboot for several days that FireFox throws memory-leak fits!!

But it could also be a sign of some really F***ED UP problem with my entire code-base!! (That seems highly unlikely, but you never know?!)

It would be really devastating to upload my client’s website to our live webserver, and User #1 comes along, creates an error, and the whole website PUKES!!! :hushed:

Any ideas???

It looks like I lied about something…

In my “errors.php” script, I do have a reference to phpMailer( ) - which e-mails the Admin when there is an error.

I just commented out the one line to phpMailer, and suddenly my Error Page loaded instantly!!

So, I think, this has something to do with me calling phpMailer…

Sounds like it. Can you post the php mailer portion (be sure to remove any sensitive info)?

if ($resultsType == 'error'){
    $from = ADMIN_EMAIL;
    $fromName = 'ACME';
    $to = ADMIN_EMAIL;
    $subject_Error = 'Re: Error: ' . $resultsCode . '   (' . $currTime . ')';
    $body_Error =    "<table>\n";
    $body_Error .=    and so on...
    $body_Error .=    "</table>\n";

//        callPHPMailer($from, $fromName, $to, $subject_Error, $body_Error);

}
function callPHPMailer($from, $fromName=NULL, $to, $subject, $body){

    // Initialize Variables.
    $results = FALSE;

    // Access Email Classes.
    require_once(HOME . 'outside_root/PHPMailerAutoload.php');

    // Connect to Email.
    require_once(EMAIL_SETTINGS_PATH);

    $mail = new PHPMailer;

    // Email Server Log-in Credentials
    $mail->isSMTP();                
    $mail->Host = 'xx.yy.zz.aa';
    $mail->SMTPAuth = true;
    $mail->Username = EMAIL_USERNAME;
    $mail->Password = EMAIL_PASSWORD;
    $mail->SMTPSecure = 'ssl';
    $mail->Port = EMAIL_PORT;

    // Email Message Details
    $mail->From = $from;
    $mail->FromName = $from;
    $mail->addAddress($to);

    $mail->isHTML(true);

    $mail->Subject = $subject;
    $mail->Body = $body;

    $results = $mail->send();

    return $results;

}//End of callPHPMailer



In your error handling script, are you able to flush the output buffer to the browser before invoking callPHPMailer() ? The delays that you’re experiencing are typical when you engage in the process of sending emails (or indeed any other network related operation) in between receiving a request and returning a response.

A better approach would be to queue the details of the email (this could be something as simple as a new database table with to, from, subject, body and sent status columns as a minimum, if you’re not able to install a more appropriate queue system - beanstalkd is good for starters) and then have another script do the actual sending in a separate process (either as a cron or as a daemon)

If you only comment out the $mail->send(); line do you still get instant loading?

I’m not saying is the problem, but it could be A month or two ago I notice I was having a problem with PHPMailer. An stumbled accross a solution and the following is the solution I came up with:

if (filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_URL) == "localhost") {
  $this->mail->isSmtp(); // Local Host:
  $this->mail->Port = EMAIL_PORT; // Local Host Port: (Usually 587)
} else {
  $this->mail->isSendMail(); // Remote Host:
}

If I do that, just like commenting out the call to the function, my error page loads so quickly I am not even completely done clicking “Submit Form”!

I have no clue what you are recommending…

Open a terminal on your Mac and run the following command

ping <your smtp server>

Example:

ping google.com

You’ll get a lot of output, let it run for at least a minute and then press CTRL + C (maybe Command C on a Mac), then paste the output here.

Following that, you may want to run a traceroute too.

You can also use these instructions:
http://support.lexisnexis.com/us_en_us/record.asp?bRFS=1&ArticleID=10228

I have no idea if @Pepster’s instructions would solve your issue, but they are using SMTP for local development and sendmail when it isn’t local development (or so it seems).

Given that the error page loads instantly when you comment out the phpMailer reference…

and given that when the code is in place, sometimes it’s fast and sometimes not…

I’d say that there is a pretty good chance that the issue is with the mail server and not your code. Especially if it cropped up out of nowhere after weeks of working just fine. Someone probably updated the server OS, or the mail server app, or updated a security setting (OCH!, if the issue was a Java update, I do not envy you), or the like.

Have you checked with your host provider to see if they’ve made any changes (either to the server that you are pushing to, or their network in general) within the last week or two? Or if they’ve had any attempts of DOS or DDOS attacks on their network?

Just my $0.032856 worth.

V/r,

:slight_smile:

1 Like

I use SwiftMailer and I had a problem sending out on one of the ports (forgot to open firewall). Might be working checking your SMTP details are correct by changing the transporter to just send from localhost and see if it works.

Do you have error reporting on/anything in the logs?

 ini_set('display_errors',1);
 ini_set('display_startup_errors',1);
 error_reporting(-1);
1 Like

I have had some things come up, and can’t respond right now.

Will be in touch…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.