Forum Moderators: coopster

Message Too Old, No Replies

Very slow processing of simple script

form handler takes 60 sec to load page

         

vmills

6:09 pm on Oct 28, 2003 (gmt 0)

10+ Year Member



This is a simple script I've used and modified for several sites to process a form without a problem. But for this site, it takes 60 seconds from the time I click the "submit" button on the page that calls the script to the time the full "thank you" page loads. The script itself seems to be functioning perfectly; the only problem is the time to load the page. I thought I might have messed up the html somewhere but the resulting "thank you" page validates, and I haven't been able to find any reason for the slow times.

I'm a novice with PHP and I wonder if anyone can point me in the right direction. Does this have to be an HTML problem or could it be something with the script or server configuration? I've spent a couple hours on this to no avail, so any help would be greatly appreciated. For what it's worth I've copied the script below.

<?php
$hsDesc = stripslashes($hsDesc);
$hsFirstName = stripslashes($hsFirstName);
$hsLastName = stripslashes($hsLastName);
require ("http://www.mysite.com/hshead.php");

if (!$hsFirstName ¦¦!$hsLastName ¦¦!$hsPhone)
{
echo "<h1>Oops!</h1>
<p align=\"center\">You didn't enter the necessary contact information.<br><br>
Please press the back button on your browser to return to the form<br>
and fill in your first name, last name and phone number.<br><br>
Thank you!</p>
<img src=\"images/nav/shim.gif\" width=\"125\" height=\"190\" alt=\"\">";

require ("http://www.mysite.com/hsfoot.php");
exit;
}

else {

echo "<h1>Thank You for Your Inquiry!</h1>
<p align=\"center\">A representative from our office will contact you<br> at the phone number or e-mail address you provided.</p>
<img src=\"images/nav/shim.gif\" width=\"125\" height=\"190\" alt=\"\">";

require ("http://www.mysite.com/hsfoot.php");

mail ("email@mysite.com", "Inquiry from Web Site", "\n
NAME: $hsFirstName $hsLastName
PHONE: $hsPhone
EMAIL: $hsEmail
CONTACT PREF: $hscontact
COMMENTS: $hsDesc\n", "From: $hsFirstName $hsLastName<$hsEmail>\nReply-To: $hsEmail");
}
?>

jatar_k

7:34 pm on Oct 28, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you've used this same script on many sites I would think it's a server issue. In my experience it often comes down to email problems.

bcolflesh

7:37 pm on Oct 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you change the path in your requires to relative links, is there any difference?

vmills

9:26 pm on Oct 28, 2003 (gmt 0)

10+ Year Member



Thanks for the heads up on the email issue. I figured the host, who I've used for several other accounts, may have changed something but I didn't know what. Sure enough their support person told me I was on a new mail system that requires authentication with a valid POP username and password. I asked if he had an example script and he said no, I should know how to do it. I don't.

I thought perhaps I simply needed to add authentication to the mail function, but apparently that's not possible. I've been looking around but can't find a clear answer. Do I use sendmail? go to something like PHPMailer (seems like overkill)? Is this obvious and simple to everyone but me? Any pointers greatly appreciated. I'm on a shared server.

(By the way, isn't it odd that my script does work, though slowly, even though they said authentication is now required?)

bcolflesh

9:35 pm on Oct 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your script is using sendmail - you are already athenticated as the user your script runs under - senmail queue is probably pretty heavy or only set to process a t certain times - use PHPMailer, it may seem like overkill, but you'll only need to tweak the SMTP username and password settings to use it in your case - check their examples.

vmills

12:21 am on Oct 29, 2003 (gmt 0)

10+ Year Member



I tried PHP Mailer and didn't get it to work perfectly, but got far enough to realize that even with the SMTP authentication, it was still taking too long. I called the host back and he said they are going to check into some server issues and get back to me - sometime. He said "maybe PHP is running slow on this server." Alas, I don't know enough about PHP or server configurations to guess what could be going wrong, but now I appear to be in wait mode. In the meantime I wanted to pass along my thanks to those who posted replies.

vmills

7:02 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



I have now tested this script on a local machine without a problem and on another server under the same hosting company, also without a problem. The host has asked me if the different versions of PHP could influence how well the script functions. The two servers on which I don't have any problems run 4.1.2 and 4.3.0 (that's the local server). The one I'm having the problem with runs 4.3.2.

I'm not aware of any changes to PHP that would affect this simple script. Are you?

jatar_k

7:12 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



no, I wouldn't think there would be problems there. We have gone through all of those versions and presently run 4.3.3 and I have seen 0 impact on mailers, and we run a lot.

NickCoons

9:01 am on Oct 30, 2003 (gmt 0)

10+ Year Member



vmills,

<Sure enough their support person told me I was on a new mail system that requires authentication with a valid POP username and password. I asked if he had an example script and he said no, I should know how to do it. I don't.>

If what your support person is saying is accurate, and let's assume for a moment that it is, this is generally an anti-spam technique used by hosting companies. What I think he means is that you need to first authenticate with the POP server before using the SMTP service. This, though, doesn't explain why it ultimately ends up working, but you can give it a shot.

Basically, you'd have to use fsockopen() to make a POP3 connection to the server, log in to it, then close the connection. After this point, you will be able to send mail successfully for X number of minutes.

Open a connect on port 110, then send the following commands:
USER [username]\n
PASS [password]\n
QUIT\n

And that should authenticate you. It's odd, however, that the local server, the server that is running the service, would need to authenticate with itself before allowing itself to send mail. Or perhaps this is why it ends up working anyway after 60 seconds.

vmills

2:54 pm on Oct 30, 2003 (gmt 0)

10+ Year Member



I've just heard from the host that they've upgraded to 4.3.3 and now everything is working fine. I have no clue why 4.3.2 would present a problem, but thought I should post it here in case it is useful information to anyone else. Again, many thanks for all the input and suggestions.

Robber

6:01 pm on Nov 12, 2003 (gmt 0)

10+ Year Member



Just been doing a search on this topic as I am also getting slow scripts using mail() - fine on one server not on another - exact same script.

I dont think its the PHP version though - works fine on server running 4.2.2 but not on 4.3.3.

Havent had a chance to contact the hosting co yet but I reckon its an authentication issue as I know they use SMTP after POP, strange though that it does work eventually as NickCoons pointed out.