Answer the question
In order to leave comments, you need to log in
How to do sequential output from MySQL?
Good to everyone! In general, this is the problem. It is necessary to display records from the database and send all this data one by one to a third-party server. those. in the database, for example, there are 500 numbers and you need to transfer each number to the server one by one. if you do it like this:
$res = mysql_result(mysql_query("SELECT COUNT(*) FROM `". input($pages) ."` ". $sql_where .""), 0);
if ($res > 0) {
$req = mysql_query("SELECT * FROM `". input($pages) ."` ". $sql_where ."");
// URL для запроса POST /message
$token = 'token ';
$instanceId = '123';
$url = 'https://sitе.com/instance'.$instanceId.'/message?token='.$token;
while ($data_req = mysql_fetch_assoc($req)) {
$string = str_replace("+7","",$data_req[$data_tel_res]);
$string = str_replace("(","",$string);
$string = str_replace(")","",$string);
$string = str_replace("-","",$string);
$string = str_replace(" ","",$string);
$string = substr_replace($string, '', 0, 1);
# echo $string .'<br/>';
$data = [
'phone' => '7'. $string, // Телефон получателя
'body' => $text, // Сообщение
];
$json = json_encode($data); // Закодируем данные в JSON
// Сформируем контекст обычного POST-запроса
$options = stream_context_create(['http' => [
'method' => 'POST',
'header' => 'Content-type: application/json',
'content' => $json
]
]);
// Отправим запрос
$result = file_get_contents($url, false, $options);
}
if ($result) {
$error_404 = 'Отправленно '. $res .' сообщений!<br/>';
} else {
$error_404 = 'Ошибка отправки '. $res .' сообщений!<br/>';
}
} else {$error_404 = 'На странице '. $pages .' нет номеров!<br/>';}
Answer the question
In order to leave comments, you need to log in
This is where ajax comes in handy.
The logic is this:
First you get the number of all records in the database. Then you send it all in portions via ajax while using LIMIT in the sql query. Try to start sending 20 records at a time.
There are a lot of options, the simplest thing that comes to mind is to run the script from the console, there are no time limits and you can send as much as you like.
The second option may not be suitable or not provided by the receiving server. The request is similar to an api call, most likely it has the ability to accept several values at once in a certain format, but this is not certain ...
The third option is to increase the maximum script running time through the ini_set.
Well, and a bunch of other options: multicurl, rabbitMKU, sending by krone...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question