Answer the question
In order to leave comments, you need to log in
What is the best way to make long queries in php?
On the site, you need to constantly make large mailings to users through the cycle.
There are several thousand users, and the number is constantly growing.
If you do this through a normal php file call, it takes 50-100 seconds.
Will soon exceed set_time_limit and loops will break.
What is the best way to do such large loops?
I wanted to do it through the exec() function , but it is disabled on the hosting.
Are there any alternatives?
Or is it better to record all tasks in cron, and then call them through the php interpreter?
Answer the question
In order to leave comments, you need to log in
You have to look at the architecture.
If you need to organize mailing to users from the database, then you just need to call the script, for example, this one:
<?php
set_time_limit(0);
$message=$_POST["mess"]
function getuser(){...};
function send($user,$message){...}
while($user=getuser()){
if (!send($user,$message))
send($user,$message) #повторная отправка в случае неудачи
}
?>
If you do this through a normal php file call, it takes 50-100 seconds.Instead of sending, add a sending task to the queue, and a separate task will send it all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question