PDA

View Full Version : Need advice on coding this in php



ELD
May 12th, 2009, 03:17 PM
Basically on my script i am coding an option to email inactive members.

I currently have this:


$sql_find = "SELECT `username`, `email` FROM `members` WHERE `last_active` < $inactive_time AND `member_id` != 2";
$query_find = $db->query($sql_find);

while ($info = $db->fetch_array($query_find))
{

}
I was thinking to add a email inside the while loop but then it will use the email function for every single member, it would be better on the systems resources to use one mail function and cc all the emails right?

But then if i do it that way it can only be a generic email as i won't be able to change the username displayed in the email as it will just be sending to all.

sonicb00m
May 12th, 2009, 03:32 PM
you can email in the loop but it might be advisable to add a sleep function for a few seconds after every x emails to stop the mail server flooding the cpu.

ELD
May 12th, 2009, 03:33 PM
That is exactly what i was thinking, but what would be a good way to do it "every x mails" ?

pitje
May 12th, 2009, 04:04 PM
$sql = "SELECT `username`, `email` FROM `members` WHERE `last_active` < $inactive_time AND `member_id` != 2";
$result = $db -> query ( $sql );

$count = 0;
$max = 10; //max amounts of mail to send per batch
$sleeptime = 5; //time to sleep in seconds
while ( $info = $db -> fetch_array ( $result ) )
{
// do the things you do
// to send the mail here

if ( $count++ === $max )
{
$count = 0;
sleep ( $sleeptime );
}
}

?

ELD
May 12th, 2009, 07:03 PM
Great stuff thanks.

sonicb00m
May 14th, 2009, 10:20 AM
Depending on the server and what else is running there you might want a gap of 5-15 every 50 mails or so?

s.fox
May 14th, 2009, 03:12 PM
Hi,

Don't forget to add the database connection details, or your query will fail :)

-Ash R

ELD
May 14th, 2009, 03:13 PM
Hi,

Don't forget to add the database connection details, or your query will fail :)

-Ash R

Lol i know that of course. That is just a snippet of code i was asking about not the whole script :P

rsuresh
May 15th, 2009, 08:14 AM
hai i need to know the procedure for sending mails through a php mail function in linux.


and also i need to know the changes to apply on the php.ini file .

please help me in this regards

ELD
May 15th, 2009, 10:59 AM
Would be better to make your own thread really, keep each problem seperate.