I
I
iDrugov2017-05-14 17:36:39
linux
iDrugov, 2017-05-14 17:36:39

How to run a daemon in PHP?

I decided to make a simple bot for VK. Executed the command in the hosting SSH console:
php adress/bot/index.php - it works only while the tab is open.
I googled the nohup command with the & key and executed the following commands:
nohup php adress/bot/index.php &
nohup php adress/bot/index.php > /dev/null &
But they all stop working when the console tab is closed. Something so-so bot comes out, working only while my browser is open :)
In general, the question is how to run a php script so that it always works.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
iDrugov, 2017-05-22
@iDrugov

In general, I will write an answer in case someone will sit in the same dullness.
Specifically, my hosting has an SSH console and a Crontab task scheduler. By running the file through the console, the virtual machine runs until the tab is closed.
Crontab could help, but it can only be run once every 60 seconds - hoster limitation. Therefore, if a request arrives after 10 seconds, then there is silence for 50 seconds and then Crontab reruns the file.
This whole ballad is relevant only for a LongPoll bot (VK API), because the Callback API itself sends a request to my server and waits for an "ok" response.
Accordingly, whoever needs a bot on LP is forced to buy at least a virtual dedicated server.
Why is Callback not always suitable?
On LP, you can issue several keys for yourself, Callback can be tied to only one server. If the community already has something third-party that uses Callback, then you either have to untie it for your bot, or make another community for the bot, as I did.

S
Shirshov Alexander, 2017-05-14
@Keanor

Write a regular script, and run it through supervisor. This is how we use consumers in queues.

R
Redaicd, 2017-05-22
@Redaicd

nodes, pythons... screen is for that

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question