As you create your project, I ran into a problem - there are some user actions that can last up to several minutes. It is clear that forcing the user to wait until such long requests to the server are executed is unallowable! And then I came to the conclusion that you need to organize a queue of tasks so that the user clicks the link, a task is formed on the server, and the user is only displayed the process of performing the task.

Even sketched a sign in the database, but the solution was not universal. The created task queue can only execute shell scripts, but I would like to teach it to perform PHP logic, and so that the results of both cases are added to the database.

I heard about RabbitMQ, Apache Message Queue, but it seems to me that they are too redundant for my case. I need to do some checks on the server (the method of executing PHP code would be just useful here, and depending on the result, the tasks would continue, or not), and manipulate the accounting files, and simply "heavy" files.

Where it was possible to read how to organize such things? Can anyone come across this already, and find a solution?

The project is created on the basis of the framework Yii.

  • So what's your problem? You need a standard solution queue, read on Wikipedia. You can do on the list, for example. - PaulD
  • Listen, this is a very tasty idea for you). I understand it turns out something like a server inside the server and in php? Correct me if that. - istem
  • @istem yes, right, something like virtual (shared) hosting. - nolka
  • In python there is a celery for this. And here is how to work with it from php: PHP client for Celery - Konstantin Pavlovsky
  • When did something similar, including on Yii. In the database, create a table with tasks, enter the type field, so you can define the shell or php. Here at design "task tracker" design patterns come to the rescue. Well, then run your console script, most likely by cron (depending on the specifics of the task) and it turns out the list of tasks and executes the current one. Immediately after launching the task, it is necessary to update its status (in_progress for example) so that cron, which will start later, does not pick it up again. Fulfilled, updated status or deleted. Looking for a new one. - Barton

2 answers 2

Worker on PCP and run it on the crown. Not?

  • Yes, such a bike is also possible, but I cannot figure out how to make it so that it can execute both shell scripts and php code. Enter the field "task_type", for example?) - nolka
  • This is already some kind of pseudo turn (Time will be lost. - frops

In the course of creating your project, I encountered a problem with such a plan - there are some user actions that can last up to several minutes.

It's horrible! This is a consequence of poor database structure and scripts. What can this be done, and besides, each user for a minute or two?

Ok, processing of several tables with mathematical operations for calculating discounts for 16K customers and 25K orders. Here, yes, I have up to 8 minutes on my server, but once a day and for everyone at once, and not for each individual.

I even sketched a sign in the database, and everything would be fine, but the solution was not universal. The created task queue can only execute shell scripts, but I would like to teach it to perform php logic, and so that the results of both cases are added to the database.

In Yii, there are console applications ( and here ), use them. Do there and logic and data operations. No need to reinvent the bicycle in this case.

  • @Shrek happens anything. One of my friends (then a colleague) for such requests did a special "squeeze" out of the database (once a day). And user requests have already taken information from this squeeze. (The disadvantage is that until the "big" request is completed, it is useless to try to get the information. But under those conditions of work it was acceptable) - alexlz
  • @Shrek, when the project is supposed to work with large archives - is it a bad database structure? Alas, I do not have such capacities, such as on VKontakte, or Google, who are able to do everything on the fly) Counting discounts is a very trivial thing, and I would have realized it myself, without question here) - nolka
  • 2
    @nolka, then php doesn't suit you, but exactly consider single-threading. Look towards java. - dlarchikov
  • @ dimka3210, there is nothing to do with multithreading:] No one bothers to run php scripts in several streams:] - nolka