V
V
Vladimir Sokolovsky2013-03-04 11:34:36
PHP
Vladimir Sokolovsky, 2013-03-04 11:34:36

The simplest task queue in PHP?

Recommend the simplest task queue in PHP like python-rq for the Python language. I started looking at popular solutions like Gearman, but compared to the analogue I cited, this is some kind of monster. In Python, I can specify a decorator in front of a function @job('low', conn=my_redis_conn, timeout=5)and my entire function will simply run in the background and the web application will not wait for it to complete. And on the same Gearman, you need to write a mountain of extra code. I tried to google, but on the topic even more huge zeromq and other mq are issued, on which, by no means, it is impossible to solve the problem in a couple of lines of code.

Answer the question

In order to leave comments, you need to log in

8 answer(s)
S
Sergey, 2013-03-04
@Ualde

The task queue is solved using Gearman, here you are absolutely right.
If you want to run just a parallel process, you can fork it or create a new one.

S
Stdit, 2013-03-04
@Stdit

One of the easiest ways to organize background tasks (such as sending an email, for example) is to delegate them to a script in cron through the database. That is, write a task with arguments to a queue table, and use a timer to parse this queue with a cron. If for some reason this is not suitable (for example, due to the speed of reaction or the load on the database), then probably look towards gearman.

E
EugeneOZ, 2013-03-04
@EugeneOZ

Maybe this will be interesting: github.com/jamm/Tasks

A
Andrey Shiryaev, 2013-03-04
@Claud

You will not find simple constructions a la go in golang. Any solution one way or another will require more code and installation of additional libraries. look at Reack, there is an async library for it, but I haven’t used it myself, so I don’t know how it actually works.

V
Valery Selitsky, 2013-03-04
@WaveCut

there is also phpDaemon, which works like a classic daemon, it may well parse the task queue. In SPL, by the way, there is a structure for convenient work with queues - SplQueue .

N
nighten, 2013-06-19
@nighten

I suggest looking at RabbitMQ. www.rabbitmq.com/

K
Konstantin Kiyashko, 2014-03-19
@konst20

And on the same Gearman you need to write a mountain of extra code

And why is that?
$client = new GearmanClient();
$client->doBackground(<function>, <data>);

Just a couple of lines of code.

A
Albert, 2020-03-19
@greezly2020

Look in the direction of a very simple and lightweight like Gearman beanstalk message broker. Beanstalk is more popular than Gearman. It was first made for Facebook.
Repository:
https://beanstalkd.github.io/.
To work with PHP, install the library via Composer:
https://packagist.org/packages/pda/pheanstalk
The PHP client is frequently updated and improved, unlike Gearman, whose extension is installed via PEAR.
Read the official documentation!
I like Gearman. For example, unlike Gearman, which simply distributes tasks, beanstalkd has an API where you can send a command in the worker code to remove completed tasks from the queue.
For example, I use in one of the projects - Gearman. And if the task from the queue is executed incorrectly by the worker or not completed at all, I put it back in the high priority queue. If not performed a second time. Then I add it to the database as an error.
Learn more about Beanstalk.
1. https://badcode.ru/chto-takoie-php-ochieried-zadach/.
2. https://badcode.ru/ochieriedi-v-proghrammirovanii-...
There is also an article about the supervisor.
Redis is also used as a message queue if you want to customize your broker. The main purpose of Redis No-SQL is a database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question