I
I
Islamfon2015-09-20 09:08:42
PHP
Islamfon, 2015-09-20 09:08:42

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

3 answer(s)
M
MK, 2015-09-20
@Maxsior

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) #повторная отправка в случае неудачи
}
?>

O
OnYourLips, 2015-09-20
@OnYourLips

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.

A
Anton Izmailov, 2015-09-20
@WapGeaR

Or running the script through the console, that's business.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question