M
M
mirapi2018-06-25 21:41:50
MySQL
mirapi, 2018-06-25 21:41:50

How to make a newsletter in javascript by adding strings in the database?

Good day!
A small application has a messaging system that runs entirely in mysql. And sometimes you need to make a mailing to several users at once.
When you need to send a message to less than 500 users - php script works great. But for a larger number, duplicates often occur if you do this:

<?
$query = "SELECT `serial_num` FROM lua_account WHERE `last_login` >= '2018-06-11 00:00:00'";
$res = mysql_query( $query );

while ($item = mysql_fetch_array($res))
{
  $text = "Текст сообщения";
  
  $temp = "SELECT count(*) as count FROM lua_message WHERE `serial` = '{$item['serial_num']}' AND `Header` LIKE 'Заголовок'"; 
  $res_temp = mysql_query($temp); 
  $rows = mysql_fetch_array($res_temp);

  $message = $rows[0];
  if ($message == 0)
  {
    send_message($item['serial_num'], "Автор", "Заголовок", $text);
    $count += 1;
  }
}

send_message() - just adds the value via INSERT INTO.
To add a delay through wait - tried. The script keeps crashing after a long wait.
The essence of the question:
How can I do this in javascript? those. receives a table of user IDs, and sends 5 messages each with a wait for a second, and at this time progress is shown on the screen.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yan-s, 2018-06-25
@Yan-s

How stupid is it to do this in JS.
You just need to solve the problem in PHP correctly.
It's not clear what is your problem with duplicates? Why do they appear? How does this relate to "wait", what is the delay for?
Long-running operations, and in particular mailings, must be performed in the background. Implemented using a task queue. From the interface, add a task to the queue, and it is launched by cron in CLI mode, without restrictions on execution time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question