R
R
RMate2021-03-01 23:54:40
PHP
RMate, 2021-03-01 23:54:40

Can you help find the magic in php sdk VKontakte?

Hello.

There is a VK API, it has a limit - no more than 3 requests per second. Whoever violates - will receive an error code 6 , and a notification

Too many requests per second


There is also an official VK PHP SDK

Using it, I make such a request
$vk = new \VK\Client\VKApiClient(VK_API_VERSION);
  for ($i = 0; $i < 30; $i++) {
    $vk->messages()->send(....);
  }


Script execution time takes ~10 seconds, no errors. Which suggests that this library itself monitors the limits.

Now the most interesting thing, I checked everything, and read the code with my eyes, and searched for all sorts of sleeps, and searched for other keywords - well, there is not a word anywhere about controlling the number of requests sent.

Tell me, please, am I so inattentive, or does VKontakte work on magic?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Ernest Faizullin, 2021-03-02
@RMate

As sleeps, the request itself plays a role in you. PHP code is executed sequentially. It depends on the speed of the iteration, sometimes you are lucky and the iteration slows down for a quarter of a second. And sometimes the opposite will be done quickly and too many requests catch the error

D
Daria Motorina, 2021-03-02
@glaphire

These restrictions are laid down by the infrastructure / web servers of VKontakte, this should not be in the SDK - this is just a layer of code to facilitate work

A
Anton Shamanov, 2021-03-02
@SilenceOfWinter

protected const CONNECTION_TIMEOUT = 10;

P
Puma Thailand, 2021-03-02
@opium

So you consistently send them and are surprised?
Well, as an example from life, there is a thin tunnel one person crawls into it, you send 30 people sequentially one at a time and they crawl through and are surprised how 30 of them fit into a tunnel one wide
Well, be a fool, run 30 requests in threads and immediately see the expected result

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question