Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Background Email Send (continuos connection)??

Status
Not open for further replies.

pain4u

Technical User
Jun 26, 2001
64
US
Hello :) ...I need some help!

I'm trying to send an email out to my mailing list of a few thousand people from a database. I am able to send the email fine, however I am running into a problem with the connection being canceled (not timed out)...the web browser is giving me a 'Unrecognized response from server' error...after about 2 or 3 minutes of sending.

My script will have to be executed for about a day or 2 before it will be sent to the entire list!

I have tried using the ignore_user_abort() function, but I do not know if my script is still being executed in the background! Does anyone know how I can find out if my script is still running in the background (I am running FreeBSD)?? --OR what I can do so that my script continues to run in the background (sending email)?

I have never sent out a mailer like this using only PHP and I know it can do it...I am just having some difficulties with the script, since there are so many email's involved.

THANK YOU IN ADVANCE FOR ANY HELP! - PAINKILLER
 
This could be that your web server is timing out the script. To get around this you could increase the time allowed for a script to execute in the conf file for your webserver.

What I would do would be to write the script in perl and run it from the command line as there will be no timeout there. As far as I am aware you cannot run php from the command line.

Will.
fortytwo
will@hellacool.co.uk
 
I have the following above my code:

set_time_limit(0);

I don't know if it does anything ;-). Girish Gupta
girish@musicgoeson.com
 
This would be useful I guess if you wanted to limit the time a script to run for, set_time_limit(0); in theory allowing the script to run as long as you want. If the script is being killed by the webserver then I don't see this helping too much. Info on that function can be found here:


Will.
fortytwo
will@hellacool.co.uk
 
I have tried all of that. It runs fine for about 3 minutes and my browser gives me a 'Cannot find server' error.

I have increased my php.ini settings to allow a script to run for 2 days in seconds. And also modified my server configuration to allow persistent connections...I am getting the feeling that it is not my server or script.It seems like it is my browser canceling the connection.

Does anyone know of a setting I can adjust in Internet Explorer 5, so that it will not time out? Or maybe a function in PHP that will keep pinging the browser letting it know that it is doing something?

Any thoughts would be appreciated!

HERE IS MY SCRIPT:
<?php

$old_abort = ignore_user_abort(true);
set_time_limit(0);

$file = &quot;email_body.txt&quot;;
$x = 0;
$fd = fopen($file,&quot;r&quot;);
$body = fread($fd,filesize($file));
fclose($fd);

$logfile = &quot;email_send2.log&quot;;
$logfile2 = &quot;email_send2_skipped.log&quot;;
$fp = fopen($logfile,&quot;w&quot;);
$fp2 = fopen($logfile2,&quot;w&quot;);

$dba = array(&quot;thehost&quot;,&quot;theuser&quot;,&quot;thepass&quot;,&quot;theDB&quot;);
$link = mysql_connect($dba[0],$dba[1],$dba[2]);
if(!$link)
die(&quot;Couldn't connect to mysqld!&quot;);

mysql_select_db($dba[3],$link) or die(&quot;Couldn't open $dba[3]: &quot;.mysql_error());

$query1 = &quot;SELECT email,email_id FROM email_list&quot;;
$result = mysql_query($query1,$link);
if(!$result)
{print mysql_error();
print mysql_affected_rows();
}
while($rows = mysql_fetch_assoc($result))
{if($rows[email_id]<6000)
{if(file_exists($logfile2))
$fp2 = fopen($logfile2,&quot;a&quot;);
fputs($fp2,&quot;$rows - $rows[email_id] - $x\n&quot;);
continue;
}
else
{if(file_exists($logfile))
$fp = fopen($logfile,&quot;a&quot;);
$send = mail($rows[email],&quot;THE SUBJECT!&quot;,$body,&quot;From: myemail@myemailhere.com (My Name)\nContent-Type: text/plain\n&quot;);
ignore_user_abort($old_abort);
fputs($fp,&quot;$rows[email] - $rows[email_id] - $x\n&quot;);
$x++;
}
}
fclose($fp);
fclose($fp2);
?> [b]- PAINKILLER [/b]
 
HAHA! ...never mind! I got it to work!

It looks like it WAS my browser timing out NOT my server. So, all I did was trick my script/server into thinking that the USER aborted (I clicked the stop button instead of just letting the darn browser time it out).

And since I used the ignore_user_abort() function...it's now continuing regardless of the stop button.

So, I did a little trick there ;o~ LOL! -- I appreciate everyones help VERY much! But I got it working now, thank you anyways! :)

- PAINKILLER
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top