0

I dont know if its the right question.

The thing is that, I have a list of users and their emails stored in my database.

Now I want to send a email to all of them with the help of a loop and setting a time interval delay (may be 5-10 seconds ).

foreach($users as $user){
     //code to send the email
}

I roughly have around 50 users. So will the code execute until the loop will complete? I mean is it a correct way to do?

What if I have hundreds or even thousands of users in future?

prakashchhetri
  • 1,806
  • 4
  • 36
  • 61

3 Answers3

4

The default max execution time is 30 seconds. You can easily modify this by going to your php.ini file and changing max_execution_time option.

If you wish to modify max execution time within your PHP script, you can use this function: set_time_limit ( int $seconds ), you can also revert these changes later.

//Settings time limit to 0 will make the script execute without time limit(see comments).
set_time_limit (0);

foreach($users as $user){
     //code to send the email
}

set_time_limit (30);
Abdulaziz
  • 2,201
  • 1
  • 21
  • 35
0

http://php.net/manual/en/info.configuration.php

By default the max_execution_time is 30 seconds. But I don't understand why you would want to stall a script for 5-10 seconds for every user when you're sending an e-mail. You may want to look at a cron job instead.

0

This problem is belong to server config for maximum time execute. You can read here How can I set the maximum execution time for a PHP script?

Community
  • 1
  • 1
Davuz
  • 5,040
  • 13
  • 41
  • 61