mailing list script timout problem 
Author Message
 mailing list script timout problem

Hi all,

I wrote this script that fetches a list of email addresses from a database
and sends a newsletter to each with a "for"-loop. (look below for example)
----------------------------------------------------------------------------
-------------------
...
$sent = 0;
$row = mysql_fetch_assoc($query);

for ($i = 0; $i < mysql_num_rows($query); $i ++) {
    $mailTo = $row['email']; // addressee
    $subject = 'MyNewsletter'; // subject
    $msg = $body; // message body

    $sendIt = mail($mailTo, $subject, $msg, $mailFrom): //construct email
    if ($sendIt) {
        $sent++;
    }

Quote:
}

...
----------------------------------------------------------------------------
-------------------

I've noticed that at times the script doesn't make it to the end of the
list, which contains about 200 entries, I guess this is because of the
execution time limit set by my host, or php itself.

If anyone has any ideas on how to work around this, I would very much
appreciate your help.

tia,

somaBoy MX



Tue, 25 Oct 2005 06:14:16 GMT  
 mailing list script timout problem
hi somaBoyMX,

somaBoyMX was scribbeling:
[..]

Quote:
> the list, which contains about 200 entries, I guess this is because of
> the execution time limit set by my host, or php itself.

> If anyone has any ideas on how to work around this, I would very much
> appreciate your help.

you can use:
http://www.php.net/manual/en/function.ini-set.php
and:
http://www.php.net/manual/en/function.set-time-limit.php

to change the timeout value (if allowed)
hth andreas
--
collect xul annotations: http://xul.andreashalter.ch/



Tue, 25 Oct 2005 14:37:50 GMT  
 mailing list script timout problem


...

Quote:
> you can use:
> http://www.php.net/manual/en/function.ini-set.php
> and:
> http://www.php.net/manual/en/function.set-time-limit.php

> to change the timeout value (if allowed)

...

...thanks.

Do you figure this would work?:
...
$sent = 0;
$row = mysql_fetch_assoc($resultSet);
$numRows = mysql_num_rows($resultSet); // get # of results
$set_time_limit(5*$numRows); // add an additional timeout of five seconds
for each email

for ($i = 0; $i < mysql_num_rows($resultSet); $i ++) {
    $mailTo = $row['email']; // addressee
    $subject = 'MyNewsletter'; // subject
    $msg = $body; // message body

    $sendIt = mail($mailTo, $subject, $msg, $mailFrom): //construct email
    if ($sendIt) {
        $sent++;
    }

Quote:
}

...

somaBoy MX



Tue, 25 Oct 2005 17:05:29 GMT  
 mailing list script timout problem
somaBoyMX was scribbeling:

Quote:
> $set_time_limit(5*$numRows); // add an additional timeout of five
> seconds for each email

i think you should use a dedictaed list software to do this.

but for small amounts of recipients it might work.

hth andreas
--
collect xul annotations: http://xul.andreashalter.ch/



Tue, 25 Oct 2005 17:17:08 GMT  
 mailing list script timout problem

Quote:

> i think you should use a dedictaed list software to do this.

> but for small amounts of recipients it might work.

My ISP doesn't allow mass mailings :(
Also I like to integrate the mailing list system tightly with the website.

thanks for all the help!

somaBoy MX



Tue, 25 Oct 2005 17:23:35 GMT  
 mailing list script timout problem

Quote:


>>i think you should use a dedictaed list software to do this.

>>but for small amounts of recipients it might work.

> My ISP doesn't allow mass mailings :(

Then why are you doing this? It sounds like it would conflict with your
ISPS TOS or AUP - which could get your account removed if you get
complaints.

Quote:
> Also I like to integrate the mailing list system tightly with the website.

Usually what I'd do is put set_time_limit(20) inside the for loop so
that there is a 20s limit for each mail - just in case.

--

PHP POSTERS: Please use comp.lang.php for PHP related questions,
              alt.php* groups are not recommended.



Tue, 25 Oct 2005 20:41:36 GMT  
 mailing list script timout problem

Quote:
> My ISP doesn't allow mass mailings :(
> Also I like to integrate the mailing list system tightly with the website.

> thanks for all the help!

> somaBoy MX

You can not use PHP to send large amount of e-mails. PHP can send about 200
emails, but that's it. However if you don't want to use majordomo, ezmlm,
esquire or any other mailing list software you can try Mojo mail. It can
send mails in batches, so it won't timeout and it won't burn down your
sendmail.


Tue, 25 Oct 2005 20:49:57 GMT  
 mailing list script timout problem


Quote:
>Hi all,

>I wrote this script that fetches a list of email addresses from a database
>and sends a newsletter to each with a "for"-loop. (look below for example)
>----------------------------------------------------------------------------
>-------------------
>...
>$sent = 0;
>$row = mysql_fetch_assoc($query);

>for ($i = 0; $i < mysql_num_rows($query); $i ++) {
>    $mailTo = $row['email']; // addressee
>    $subject = 'MyNewsletter'; // subject
>    $msg = $body; // message body

>    $sendIt = mail($mailTo, $subject, $msg, $mailFrom): //construct email
>    if ($sendIt) {
>        $sent++;
>    }
>}
>...
>----------------------------------------------------------------------------
>-------------------

>I've noticed that at times the script doesn't make it to the end of the
>list, which contains about 200 entries, I guess this is because of the
>execution time limit set by my host, or php itself.

>If anyone has any ideas on how to work around this, I would very much
>appreciate your help.

>tia,

>somaBoy MX

Just a quick thought.. To prevent killing sendmail with large hunks of
e-mail what if you combined the time out with a sleep after a set
count? Use set_time_out() to keep PHP from bailing out. Then use sleep
to keep from drowning sendmail. Let's say we have 2000 e-mail
messages. To be safe, you could break them into blocks of 100.
So we would have  message blocks.  After sending 150 we sleep say 10
seconds and send another hundread.

Another (possible) solution.
Ok. Let's say the mailing list in question is super popular and we
have 20,000 users. Obviously, at this point we should be able to
afford a decent mailing list manager, but for the sake of argument we
don't have one. The above aproach, wich is already screaming in agony,
simply drops dead with a list this size.

Step 1.
With blocks of 150 that gives us about 134 blocks (with the last one
having less than 150).

Step 2.
Fake the schedule. With super massive list like this one, the only way
I can see to do it is by scheduling the e-mails several minutes apart
using a cron job. We could eaisly create a script will queary the
database, get a block, send it, record where it stopped and die.
The cron job would execute this script several times, with a delay of
say 5  minutes between script calls.  This would take about 11 our 12
hours to send all this junk. Not very practical I must admit.
Lowering the delay by even a small amount, or increasing the batch
size by a small amount will have a drastic effect (batches of 200 sent
3 minutes apart would only  take about five hours. )

Step 3.
Find new ISP. Apologize to the developers of both PHP and sendmail and
promise never to do  it again.

The above examples make an attempt to be at least a little bit
friendly to the ISP and sendmail.  Maybe it would work, maybe not.

Comments?

---
David Hamilton
www.potentialcreations.com



Tue, 25 Oct 2005 21:36:10 GMT  
 mailing list script timout problem



Quote:


> >I wrote this script that fetches a list of email addresses from a
database
> >and sends a newsletter to each with a "for"-loop. (look below for

example)
I have this same problem but I can send about 3000 mails.  I found out that
the sendmail buffer was drowned.
Extending those timeouts didn't solve my problem.

Suggestions:
- upgrade bandwith
- import a little retry system.  When mail(); returns an error, use the
sleep(); function for some seconds and try again.  This simple solution
works fine for me.



Tue, 25 Oct 2005 23:54:02 GMT  
 mailing list script timout problem


Quote:
> Then why are you doing this? It sounds like it would conflict with your
> ISPS TOS or AUP - which could get your account removed if you get
> complaints.

it may be against my ISP's t.o.s but not against my webhost's :)

I figure if I run this scrip on a remote server, my ISP doesn't have
anything to say on this. And even then, it's not as if I'm going to spam
anyone. This is a regular newsletter I'm talking about...

Quote:
> Usually what I'd do is put set_time_limit(20) inside the for loop so
> that there is a 20s limit for each mail - just in case.

good hint, I'll keep it in mind.


Wed, 26 Oct 2005 01:30:53 GMT  
 mailing list script timout problem


Quote:
> You can not use PHP to send large amount of e-mails. PHP can send about
200
> emails, but that's it.

so what about
* phpMailer
* Bulk Mailer X
* phpNewsletter
* Relatamail
* MyMail
* RGNmailer
* PHPMailList
* ...

all of them are php-based mass mailing scripts/classes/solutions. I haven't
tried any, just figured I'd try and write one myself...



Wed, 26 Oct 2005 01:36:57 GMT  
 mailing list script timout problem

Quote:

> so what about
> * phpMailer
> * Bulk Mailer X
> * phpNewsletter
> * Relatamail
> * MyMail
> * RGNmailer
> * PHPMailList
> * ...

> all of them are php-based mass mailing scripts/classes/solutions. I
haven't
> tried any, just figured I'd try and write one myself...

They all timeout. Maybe Octeth is OK, I'm not sure...

PS
If you want commercial service, you can contact me.



Wed, 26 Oct 2005 06:32:52 GMT  
 mailing list script timout problem


Quote:
> PS
> If you want commercial service, you can contact me.

ROTFL!


Fri, 28 Oct 2005 16:53:43 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Announcement: New Mailing list script-fu@yahoogroups.com

2. Announcement: New Mailing list script-fu@yahoogroups.com

3. Mod_dtcl (web server side scripting) mailing list.

4. newbie with a php validation form mail script problem

5. ANNOUNCE Take 2: python-win32 mailing list on mail.python.org

6. Spreading load for large mailing lists (mail...)

7. ANNOUNCE Take 2: python-win32 mailing list on mail.python.org

8. Squeak Mail List Problems

9. Newbie, File generating question and mailing list problem..

10. Mailing list problem?

11. GtkAda mailing list? (problem GtkAda on Windows)

 

 
Powered by phpBB® Forum Software