Jump to content

timeout error


merylvingien

Recommended Posts

Hi fellas, i am trying to build a page so that i can email all the users of my site. Sort of a mass mail page.

Trouble is when i test this on my local machine, the code works ok, and starts trying to send the emails (although i havent setup a mailer on my localhost)

 

But for some reason it stops and gives me this:

 

Fatal error: Maximum execution time of 60 seconds exceeded

 

I am only trying to send 70 or so emails.

 

Ive actually used some code that i foud on here and just changed it a bit:

 

$con = mysql_connect("localhost", "root", "");
if (!$con)
  {
  die('error');
  }
$db_selected = mysql_select_db("table",$con);

$message= $_POST['message'];
$from = "[email protected]";

$sql = mysql_query("SELECT email FROM table");
while($line = mysql_fetch_assoc($sql)){

   $email[]  = $line;

}


foreach($email as $e){

//Remove whitespace in case there is some.
$e['email'] = trim($e['email']);


mail($e['email'],"Wasp Control UK",$message,"From: $from");

echo "Message sent to {$e['email']}";
usleep(500000);
}

 

Anyone know why this would time out?

Link to comment
https://forums.phpfreaks.com/topic/183593-timeout-error/
Share on other sites

You need to add:

 

set_time_limit(600);
ignore_user_abort(1);

 

set_time_limit(seconds) sets how long the script is allowed to run for without stopping.

ignore_user_abort(1) sets that the script should not stop parsing if the user closes their browser window.

 

 

That done the trick  ;D

Link to comment
https://forums.phpfreaks.com/topic/183593-timeout-error/#findComment-969066
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.