K
K
KirSupi2021-09-07 10:25:50
PHP
KirSupi, 2021-09-07 10:25:50

How to make a queue of data between PHP and Python?

There is a php script that receives a bunch of data and generates a bunch of input data for python. Then some mechanism should transfer this data to the ever-working python (tg-bot).
Example:
PHP receives numbers, and the bot should send a message to the person with every second number
Let's say PHP received the numbers 1 and 10
It writes the user id and the text of the message to the queue:
12341234 | 'number 1'
12341234 | 'number 3'
12341234 | 'number 5'
12341234 | 'number 7'
12341234 | 'number 9'
Python checks the queue regularly (or some mechanism in the queue yanks Python to peek when something appears), takes the data (which is itself removed from the queue), and sends the desired text to the right user

Of the implementation ideas, only a MySQL plate, but with a heavy load at some point, PHP and Python can simultaneously get into the database and give an error, but the queue needs to work instantly, without waiting for PHP to load all the data (for example, PHP wants to load 10k tasks , and the first 100 loaded are immediately sent to python), i.e. if the task queue is empty and the bot is idle, then as soon as PHP puts the data in the queue, they are immediately transferred to the bot

MB are there any ready-made solutions / libraries?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vasily Bannikov, 2021-09-07
@vabka

The word "queue" suggests RabbitMQ - it has libraries for both php and python

A
Alexey Cheremisin, 2021-09-07
@leahch

I recommend redis. Simple, stylish, youthful!

R
Roman Kitaev, 2021-09-07
@deliro

RabbitMQ
Redis
NATS Streaming
Linux FIFO
Even simple HTTP
Thousands of them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question