G
G
Gonlif2016-10-12 14:18:07
In contact with
Gonlif, 2016-10-12 14:18:07

What is the best way to solve (PHP, VK API)?

Hello, I want to know your opinion on the best way to solve this problem.
There is a written script that receives a message through vk api and looks for an answer in the database, after which it sends the desired answer (roughly speaking, a typical bot). The problem is that the script is hosted and works while the page is open in the browser. If it is closed, therefore? and no questions will be accepted and no answers will be created.
A constantly open browser with a page is not an option, cron cannot cope with this task either, because there is no specific time, a question from the user can come at any time.
How can you implement the same script that would run all the time?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Petr Flaks, 2016-10-13
@neluzhin

I wouldn't say that cron can't handle it. On cron, what bikes were not written, so it's worth a try.
But let's put aside the crutches and try to do everything according to Feng Shui first. Do you accept messages from users in the Community LAN? If yes, then Callback API is your true friend. Using this thing, VK itself will report POST requests to your script when you have been written to the community LAN. And already there you can immediately select the text for the answer and answer it using standard API methods.
If you receive messages from the user's page, then get ready to collect a bicycle from the crown. On a good note, you should run 2 scripts: the first one, with an interval of ~5 seconds, will add user messages to the database, and the second one, with an interval of one second, will check this database and respond to these messages. For beauty, you can implement all this through the execute method in order to somehow bypass the restriction of 3 API calls per second.
UPD.
Also look at Long Poll . I myself have never worked with this feature, but perhaps this is what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question