[Fwd: PHP Access Violation using PEAR::Mail_smtp]

php.internals

Ben Ramsey

22 years ago
I'm forwarding this to the Internals list as a last resort and at the suggestion of someone with PHPCommunity.org. I have not received any response from php-general or pear-general (after 24 hours), and I have posted a similar posting about this issue several weeks ago (also with no response). I have just upgraded my Windows Server 2003 to the Apr 6 2004 20:12:15 build of PHP 5RC1 from snaps.php.net. Here's my phpinfo() page: http://test.alpharetta.ga.us/info.php I am not sure whether this is a bug with PHP, but I am sure that you guys can tell that. Any help at all is much appreciated. We cannot launch this site until this issue is resolved, and don't ask me to revert back to a stable version of PHP or we will have to modify much code throughout the site. ;-) Thanks, Ben -------- Original Message -------- Subject: PHP Access Violation using PEAR::Mail_smtp Date: Mon, 05 Apr 2004 13:58:31 -0400 From: lists@benramsey.com (Ben Ramsey) To: pear-general@lists.php.net, php-general@lists.php.net Newsgroups: php.general,php.pear.general I'm getting the following error when using the Mail_smtp package from PEAR: PHP has encountered an Access Violation at 0177A8B4 It does not occur everytime I use it, but even when send() returns true, e-mail messages are not being sent. However, it all worked fine a week ago when I was testing it, and I don't think anything has changed to my installation of PHP. I'm using PHP 5RC1 on a Windows Server 2003. The localhost has no built-in mail functionality, so I cannot use mail(). I must use Mail_smtp to log in to the mail server. I also have Net_SMTP and Net_Socket installed, and, like I said, when I first dropped in my code, all was working fine. My code is, as follows: <code> require_once 'Mail/smtp.php'; $smtp_settings = array( 'host' => 'localhost', 'port' => '25', 'auth' => 'LOGIN', 'username' => 'username', 'password' => 'password' ); $to = "you@example.com"; $msg = "Line 1\nLine 2\nLine 3"; $headers = array( 'Subject' => "My Subject", 'From' => "me@example.com", 'Date' => date('r'), 'Content-Type' => 'text/plain', 'X-Mailer' => "PHP/" . phpversion() ); $mail = new Mail_smtp($smtp_settings); if ($mail->send($to, $headers, $msg)) { echo "<h2>Sent successfully</h2>"; } else { echo "<h2>Not sent</h2>"; } </code> If I don't get the access violation error, I get the message "Sent successfully." Yet, I don't receive any messages. In the code for Mail_smtp (in Mail/smtp.php), I have added the following line just under the function declaration line for the send() method: echo "test"; When the access violation occurs, I get this line: PHP has encountered an Access Violation at 0177A8B4test From this, it appears to me that the access violation is not occurring when the class tries to send mail, but sometime earlier than that. However, I do not know much more about these Access Violoations, other than PHP is trying to access memory that it doesn't have permission to access. I couldn't find anything at bugs.php.net or through Google that helped much with this problem. Any help would be greatly appreciated. I am on a tight deadline, so any help ASAP would be even more greatly appreciated. ;-)
-- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey

Adam Maccabee Trachtenberg

22 years ago
On Tue, 6 Apr 2004, Ben Ramsey wrote:
> Any help at all is much appreciated. We cannot launch this site until > this issue is resolved, and don't ask me to revert back to a stable > version of PHP or we will have to modify much code throughout the site. ;-)
You will significantly improve your chances of a useful response if you pare down the code that triggers to problem to the fewest number of lines possible. Ideally, you'd also remove the PEAR class and just strip out the lines that trigger the bug. Then file a bug report on http://bugs.php.net with the information. -adam
-- adam@trachtenberg.com author of o'reilly's php cookbook avoid the holiday rush, buy your copy today!

Ben Ramsey

22 years ago
AT> You will significantly improve your chances of a useful response if AT> you pare down the code that triggers to problem to the fewest number AT> of lines possible. AT> AT> Ideally, you'd also remove the PEAR class and just strip out the AT> lines that trigger the bug. I will try to do this. Unfortunately, I goofed up and stated that it could not send e-mail at all. This was do to setting my authentication method to the wrong thing. When I changed it back to LOGIN, it will now send e-mail messages flawlessly. However, every 4th or 5th time, it will not send the message and will display a blank page with: PHP has encountered an Access Violation at 0177A9D4 Like I said, I'll try to pare down the code, but I feel out of luck here, since it's occurring intermittently. Thank you for your time.
-- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey

Mark Spruiell

22 years ago
Ben, It may not be related to your situation, but I just submitted this bug report: http://bugs.php.net/bug.php?id=27895 Take care, - Mark

Ben Ramsey

22 years ago
I've been told by someone here to pare down my code and submit a bug report. However, paring down my code corrected the problem, so I'm still not sure what a PHP Access Violation error is. Following is the post I made to php-general with my "solution." Am I on the right track with my guess as to what may have been occurring with the Access Violation errors, and should I still submit a bug report? ----- So, I found a solution to my problem. I still do not know what was causing the PHP Access Violation errors, but I have an idea, which I will relate in this message. As many suggested, I have pared down my mail sending class by rewriting it down to about 250 lines of code. Previously, the PEAR::Mail::smtp class had much fewer lines of code, but if you count all of the other files it had to include, then it was a whopping amount of code. The difference here is that I am only using one class now to send mail, whereas the PEAR::Mail::smtp class was using about 5 different classes. Let me walk you through them. Mail::smtp included and extended the Mail class. The Mail class included and extended the PEAR class. The send() method of Mail::smtp included the Net::SMTP class and created an object of that class. The Net::SMTP class included the PEAR and Net::Socket classes (and optionally checked for and included the Auth::SASL class). The Net_SMTP() contstructor created a Net::Socket object. The Net::Socket class included and extended the PEAR class. So, in all, that's about 5 classes that Mail::stmp needed. Once I got it down to one class, the Access Violations disappeared. So, here's what I think was happening with the classes based on some of the information I have been told. I've been told that the Access Violation errors are probably caused when PHP tries to access a space of memory that it doesn't have permission to access. From this, I'm gathering that the sheer number of classes needed and objects and variables created confused PHP so that it wasn't sure what pointers pointed to the correct space in memory. (Again, I'm out on a limb with this guess.) Because the pointer lost its space in memory (I'm guessing that's what happened), PHP tried to access a space that it either no longer had permission to access or it never had permission to access. Make sense? I'm sharing this here because several people expressed an interest in knowing how it got resolved.
-- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey