prakashchhetri
prakashchhetri

Reputation: 1816

How long can a php code execute?

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?

Upvotes: 0

Views: 521

Answers (3)

Abdulaziz
Abdulaziz

Reputation: 2211

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);

Upvotes: 4

Davuz
Davuz

Reputation: 5276

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?

Upvotes: 0

user1508519
user1508519

Reputation:

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.

Upvotes: 0

Related Questions