Answer the question
In order to leave comments, you need to log in
Sends and sends a message, why doesn't it lag behind?
I heard that after I received a request from VKontakte, it is necessary for him to answer Ok so that he lags behind you. But, I am not far behind. I'm making a VK bot, and VK constantly sends the same request to my site....
/*
*/
class Group {
public function __construct($params = [], $data = []) {
$this->token = $params->token;
$this->version = $params->version;
$this->data = $data;
}
public function reply($message = null) {
return $this->sendMessage($this->data->object->message->peer_id, $message);
}
}
/*
*/
$group = new Group($CONFIGURATION->GROUP, json_decode(file_get_contents("php://input")));
/*
*/
echo 'Ok';
/*
*/
switch($group->data->type) {
case 'confirmation': {
echo $CONFIGURATION->GROUP->CONFIRMATION;
break;
}
case 'message_new': {
echo 'Ok';
$group->reply('Hello world!');
echo 'Ok';
break;
}
}
/*
*/
echo 'Ok';
Answer the question
In order to leave comments, you need to log in
Catch. This function sends ok and terminates the connection to the VC so that it thinks that the script has finished executing.
function sendOK() {
set_time_limit(0);
ini_set('display_errors', 'Off');
// для Nginx
if (is_callable('fastcgi_finish_request')) {
echo 'ok';
session_write_close();
fastcgi_finish_request();
return True;
}
// для Apache
ignore_user_abort(true);
ob_start();
header('Content-Encoding: none');
header('Content-Length: 2');
header('Connection: close');
echo 'ok';
ob_end_flush();
flush();
return True;
}
Everything is correct, VK checks the answer, it should be "ok", but the code shows that even if nothing is done, it will receive the answer "ok". In general, you need to remove the extra line output, "ok" should be displayed once. Also, it should be in small letters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question