I don’t understand how User Long Poll API works. Can you tell? I figured it out with the Bots Long Poll API, but not really with the user. Two questions:

  1. How to make it clear to the VC server where to send events?
  2. How to handle events on my server?

I did this:

  1. First I got server, key and ts using messages.getLongPollServer.
  2. I sent a request of this type from my server (as in the documentation):

    https: // {$ server}? act = a_check & key = {$ key} & ts = {$ ts} & wait = 25 & mode = 2 & version = 3 changed the variables to those in clause 1

  3. And then what? VC will send events to the address of the page from which the request was to item 2 or how?

If so, how to handle them? For example, you just need to write all the events to a file. Then I write in PHP like this:

header("Content-Type: text/html; charset=utf-8"); header("HTTP/1.0 200 OK"); $event = json_decode(file_get_contents('php://input'), true); file_put_contents('1.txt', $event); 

But something does not record anything. I send myself messages, and the file is empty.

    1 answer 1

    It is strange that you say that you have sorted out the Bots longPoll, because the principle is the same.

    If you refer to the same help VC , even there it is quite clearly described.

    And now, I will try on the fingers:

    • Long polling is when you throw an http request to the server. But the server is not obliged to answer you right away. He waits for about 30 seconds, and then sends you an empty answer (if nothing happens).

    • If something happens, the server responds to your request before 30 seconds.

    • After the server responds to you, you throw a new request to it, and it will respond to you either after 30 seconds, or earlier, if something happens.

    • The time after which the server responds and terminates the connection is limited to 30 seconds (you can set it yourself, allowing you to, if I'm not mistaken), because There may be problems with some network equipment, which itself ruins such a connection after 30 seconds.

    • And yes, you tell the server where to throw the answer when you send a request, because the server is able to determine where it came from)

    Now consider the situation step by step:

    1. You send a request to the server
    2. It takes 10 seconds
    3. The server understands that something has happened, answers you ( {ts: ..., updates: [...]} ), the connection is closed
    4. You immediately open a new connection with the next request.
    5. It takes 30 seconds, but during this time the server had nothing to send to you
    6. After the time expires, the server sends you an empty response (VK sends in the {updates:[]} format, if I'm not mistaken).

    Somehow, I hope that is understandable.

    And yes. I am not pkhp-shnik, but I need to parse as json exactly that “page”, which will be returned to you by the request to the address https://{$server}?act=a_check&key={$key}&ts={$ts}&wait=25&mode=2&version=3 .