A
A
adrenalinruslan2020-01-19 21:47:31
PHP
adrenalinruslan, 2020-01-19 21:47:31

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

3 answer(s)
K
Kirill Minovsky, 2020-01-19
@Runnin

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;
    }

by https://github.com/digitalstars/simplevk

D
dmalapsh, 2020-01-19
@dmalapsh

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.

U
Uno, 2020-01-20
@Noizefan

In general, from the point of view of the hardness of architecture, your code should be ready for such difficulties. Why else would there be such a code?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question