Script timing out?

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
Souris
Forum Newbie
Posts: 6
Joined: Wed May 07, 2008 3:25 pm

Script timing out?

Post by Souris »

Hi,

I am fairly new to both swift and PHP, I have adapted a script example that Chris posted to handle a form. My adapted script should loop through approximately 400 email addresses in my database, but around about half way though running the script I get the IE "cannot display the webpage" screen.

I know that atleast 100 of the recipients receive the email because the guy who I built the site for gets his email and he is 107th in the database, but further than that I don't know how many subscribers are recieving the email.

I have posted the script below and wondered if anyone could see any obvious errors.

Any help would be gratefully appreciated.

Thank you.

Code: Select all

require_once "../Connections/connAgchem.php";
require_once "../lib/Swift.php";
require_once "../lib/Swift/Connection/SMTP.php";
require_once "../lib/Swift/Plugin/AntiFlood.php";
 
// Query database
mysql_select_db($database_connAgchem, $connAgchem);
$query = "SELECT Username FROM subscribers WHERE Email_Me = 'Y'";
$result = mysql_query($query) or die(mysql_error());
 
//Copy into global variables
$ProdGroup = $_POST['ProductGroupName'];
$Country = $_POST['Country'];
$ActiveIng = $_POST['ActiveIng'];
$Conc = $_POST['Concentration'];
$Formula = $_POST['Formula'];
$Tradename = $_POST['Tradename'];
$Type = $_POST['Supplier'];
$Quantity = $_POST['Quantity'];    
$Region = $_POST['Country'];                      
$ID = $_POST['ID'];
$Status = $_POST['Sent'];
                   
//Enable disk caching if we can
if (is_writable("/tmp"))
{
    Swift_CacheFactory::setClassName("Swift_Cache_Disk");
    Swift_Cache_Disk::setSavePath("/tmp");
}
 
//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
 
//Reconnect after 200 emails, but wait for 10 seconds first
$swift->attachPlugin(new Swift_Plugin_AntiFlood(100, 10), "anti-flood");
 
//Create the sender from the details we've been given
$sender =& new Swift_Address("webactivity@agchemaccess.co.uk");
 
//Create the message to send
$body = "The agrochemical shown below has recently been added to our on-line data base. As part of our AgChemConnect® service we are keeping you informed." . "\r\n" . "\r\n" . "Agrochemical: " . $ProdGroup . "\r\n" . "Active Ing: " . $ActiveIng . "\r\n" . "Trade Name: " . $Tradename . "\r\n" . "Concentration: " . $Conc . "\r\n" . "Quantity: " . $Quantity . "\r\n" . "Formula: " . $Formula . "\r\n" . "Region: " . $Region . "\r\n" . "Type: " . $Type . "\r\n" . "\r\n" . "For more information about this agrochemical please reply to this email, or telephone +44(0)1603 624413" . "\r\n" . "\r\n" . "Kind regards" . "\r\n" . "The AgChemAccess team" . "\r\n" . "\r\n" . "To unsubscribe from AgChemConnect® email alerts please update your web site profile at http://www.agchemaccess.co.uk";
 
$message =& new Swift_Message("New Agrochemical Added");
$message->attach(new Swift_Message_Part($body));
 
//Try sending the email
$recipients =& new Swift_RecipientList();
while ($row = mysql_fetch_array($result)) 
{
 $recipients->addTo($row['Username']);
}
 
$sent = $swift->batchSend($message, $recipients, $sender);
//$sent = $swift->send($message, new Swift_Address($subEmail), $sender);
 
//Disconnect from SMTP, we're done
$swift->disconnect();
 
if ($sent)
{
    header("Location: ./current_agchems.php");
    exit();
}
else
{
    header("Location: ./current_agchems.php?error=sending_failed");
    exit();
}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Script timing out?

Post by Chris Corbyn »

Code: Select all

<?php set_time_limit(0); ?>
All PHP scripts timeout after 30 seconds by default.
Souris
Forum Newbie
Posts: 6
Joined: Wed May 07, 2008 3:25 pm

Re: Script timing out?

Post by Souris »

Thanks for the reply.

I previously had:

Code: Select all

set_time_limit(300);
at the beginning of the posted script but as this didn't work so I removed it and

Code: Select all

set_time_limit(0);
also has had no effect.

Is there anything else that I might have missed
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Script timing out?

Post by Chris Corbyn »

What error do you get? Some SMTP server's have restrictions on the volume of mail you can send. It's hard to offer you a solution without a copy & paste of the error message though ;)
Souris
Forum Newbie
Posts: 6
Joined: Wed May 07, 2008 3:25 pm

Re: Script timing out?

Post by Souris »

Thanks for the reply.

The only problem is that I am not receiving any specific error only a "Internet Explorer cannot display the webpage" screen as shown below, but I doubt that this is of any help. :?
Internet Explorer cannot display the webpage

Most likely causes:
You are not connected to the Internet.
The website is encountering problems.
There might be a typing error in the address.

What you can try:
Diagnose Connection Problems

More information

This problem can be caused by a variety of issues, including:

Internet connectivity has been lost.
The website is temporarily unavailable.
The Domain Name Server (DNS) is not reachable.
The Domain Name Server (DNS) does not have a listing for the website's domain.
If this is an HTTPS (secure) address, click Tools, click Internet Options, click Advanced, and check to be sure the SSL and TLS protocols are enabled under the security section.

For offline users

You can still view subscribed feeds and some recently viewed webpages.
To view subscribed feeds

Click the Favorites Center button , click Feeds, and then click the feed you want to view.

To view recently visited webpages (might not work on all pages)

Click Tools , and then click Work Offline.
Click the Favorites Center button , click History, and then click the page you want to view.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Script timing out?

Post by John Cartwright »

Anything in the php error logs?
Souris
Forum Newbie
Posts: 6
Joined: Wed May 07, 2008 3:25 pm

Re: Script timing out?

Post by Souris »

Sorry, error logging is disabled, so no.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Script timing out?

Post by Chris Corbyn »

Are you trying to mass mail via a web browser? The browser will always time out before PHP does (after say 3 minutes or so). You need to use command line or add ignore_user_abort() and close the window if you want to mass mail successfully.
Souris
Forum Newbie
Posts: 6
Joined: Wed May 07, 2008 3:25 pm

Re: Script timing out?

Post by Souris »

Thank you.

Sorry for the delayed reply!

Can you see anything in the script that may be causing duplicates as all recipients are receiving two emails.

TIA
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Script timing out?

Post by Chris Corbyn »

That's usually caused not be an error in the script itself, but by a logic error which means you include() the script twice ;)
Souris
Forum Newbie
Posts: 6
Joined: Wed May 07, 2008 3:25 pm

Re: Script timing out?

Post by Souris »

Thanks very much for your help Chris :D

I am still having problems with the script but I have rewritten it with some help, although it has some issues :?

Could you recommend a good host with regards to mass mailing, the site using swift is currently on GoDaddy and after checking the forum and their website I don't know how I have got any emails to send!

Many thanks
Post Reply