Page 1 of 1

[Solved?] Swift Causes Page Load To Stall

Posted: Wed Oct 25, 2006 9:48 am
by nickvd
I AM using the latest version (2.1.17), which fixed the preg_match warnings, thanks!

Code: Select all

<?php
require_once('inc/Swift.php');
require_once('inc/debuglib.php');
require_once('inc/Swift/Connection/Sendmail.php');

$connection = new Swift_Connection_Sendmail;
$swift = new Swift($connection);
$swift->autoFlush(false);

if ($swift->isConnected()) {
   echo "<h1>CONNECTED</h1>";
   $swift->addPart("This is the HTML Email", 'text/html');
   $swift->addPart("This is the Plaintext Email");
   $swift->send(
      array(
         array("nick","nickvd@gmail.com"),
         array("bob","ecompulab3@westniagara.com")
      ),
      "webmaster@whyallthetrouble.com",
      'This is an email test, why does it hang?'
   );
}
dump($swift->transactions);
dump($swift->errors);
?>
The code above... "works"... In that, the emails get sent, and I recieve them perfectly, but for some reason, the page never stops loading... My next step is going to be capturing the packets themselves to see where the problem lies, but last time i tried, i came up blank (the server just seems to stop sending data w/o closing the connection).

The page displays everything until the last transaction message:

Code: Select all

time	0.29318100 1161787324
response	250 2.0.0 k9PEg1TI020529 Message accepted for delivery
Then stops loading data... firefox never stops loading the page....

Posted: Wed Oct 25, 2006 9:49 am
by nickvd
I just looked at the headers from one of the emails, and I'm seeing the following:

Code: Select all

Message-Id: <200610251442.k9PEg1TH020529@luna.behosting.com>
X-Authentication-Warning: luna.behosting.com: www owned process doing -bs
To: "nick" <nickvd@gmail.com>
Any Clues?

<edit>
I just tried removing multiple senders/parts, turned off autoflush, so it's pretty much a plain jane test... and nothing :(

Posted: Wed Oct 25, 2006 10:21 am
by nickvd
I think I've narrowed it down to swift failing to end the communication (send the "QUIT" command), The following code "works":

Code: Select all

<?php
require('inc/Swift.php');
require('inc/Swift/Connection/Sendmail.php');
require('inc/debuglib.php');

$connection = new Swift_Connection_Sendmail('/usr/sbin/sendmail -bs');
$swift = new Swift($connection);
if ($swift->isConnected()) {
   echo "<h1>CONNECTED</h1>";
   $swift->autoFlush(false);
   $swift->addPart("This is the HTML Email", 'text/html');
   $swift->addPart("This is the Plaintext Email");
   $swift->send(
      array(
         array('gmail','nickvd@gmail.com'),
         array('work','ecompulab3@westniagara.com')
      ),
      'wow@itmayjustowork.net',
      'WORKING? PLEASE WORK!'
   );
}
dump($swift->transactions);
dump($swift->errors);
$swift->close();
?>
The Gmail account received the email perfectly, the westniagara account (using thunderbird) received the email, but it's content is:

Code: Select all

This part of the E-mail should never be seen. If
you are reading this, consider upgrading your e-mail
client to a MIME-compatible client.
--_=_swift-1314080577453f80471bf841.74523167
Content-Transfer-Encoding: 8bit
Mime-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

This is the Plaintext Email

--_=_swift-1314080577453f80471bf841.74523167
Content-Type: text/html; charset="ISO-8859-1"; format=flowed
Content-Transfer-Encoding: 8bit

This is the HTML Email
--_=_swift-1314080577453f80471bf841.74523167--
It's almost as if the autoFlush never happens, and it loses the boundry header...

Posted: Wed Oct 25, 2006 10:58 am
by nickvd
Sorry for the multiple posts, this problem has been killing me...

I seem to have it solved, after sending the mail, I check of there was an error, and manually flush and close the connection.

Code: Select all

if (!$swift->hasFailed()) {
      echo "<h1>SUCCESS!</h1>";
      $swift->flush();
      $swift->close();
      dump($swift->transactions);
   } else {
      echo "<h1>ERRORS!</h1>";
      dump($swift->errors);
   }
For some reason, it would work w/o doing that when using SMTP, but with sendmail, it is needed... BUG? FEATURE?

Posted: Wed Oct 25, 2006 4:38 pm
by Chris Corbyn
Sendmail is handled via an open pipe process with the process handling functions. In some PHP versions (or maybe it's sendmail versions?) it does seem to hang if you don't call close() to end the process yourself.

For PHP5 versions there's no reason I couldn't call close() from the destructor. In fact; I had added it before but decided to keep the behaviour the same between PHP4 and 5 versions. I can put that back in though.