A
A
Andreda2017-11-23 15:30:55
PHP
Andreda, 2017-11-23 15:30:55

What is the best way to implement parallel script execution in Php?

Good afternoon!
There is such a task.
The script accepts a request from the user, and you need to check the information on 30 supplier sites in parallel (the number will grow).
Analyze the answer - and give it to the user.
And these 30 queries need to be executed quickly, in parallel , not sequentially.
Multi-curl is not suitable, because after each curl, each site has its own actions, possibly additional curl requests, and other calculations.
In fact, these are 30 functions that need to be run in parallel, but the main execution time is waiting for a response from the sites, here PROXY also increases the response time.

What are the best options to use in PHP for running in parallel?

To work quickly and spend the least resources.
The following are spinning in my head:
1. Implement by running N scripts, for example, through - without waiting for a response. And thus not be able to process the response from each script. 2. Do it with pcntl - and also not be able to wait and process the response. 3. To do it using the pthreads library - here you can run 30 functions at once in 30 threads (each function in its own thread) and wait for their execution and process the results. (Currently implemented this option, but I was told that this is a bad option) Which of these options is better than the others? What are the differences between these options?shell_exec("php script.php $params")


And maybe someone else will tell you some options for php?
Or maybe it should be implemented in other programming languages, and if so, on what and using what tools?
The queue server is also not suitable yet, it is necessary to perform such an operation as quickly as possible for each request, therefore it is desirable to perform all 30 functions in parallel.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
myxasa, 2017-11-23
@myxasa

shell_exec("php script.php $params")
each script must write a response to the database or somewhere else
the main script checks by cron whether the work is finished?

S
synapse_people, 2017-11-23
@synapse_people

pcntl, you can wait for several processes to complete, who said you can't?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question