Answer the question
In order to leave comments, you need to log in
Parallel execution of operations in PHP?
Are there people here who are experienced in writing PHP scripts with parallel execution of some actions? For example, there is a web page for which information is downloaded and parsed from several sources. It is logical to parallelize these processes. How can this be technically implemented? OS linux or freebsd. There is an option to launch background processes (exec('php somescript… &')) that will perform these operations and save the result to files, while the main process will wait for these files to appear. But somehow it is not optimal, I think.
Answer the question
In order to leave comments, you need to log in
if you really just need to parse, then you can use php.net/manual/ru/function.curl-multi-exec.php ?
github.com/reactphp/react/blob/master/examples/parallel-download.php
As an option, wrap tasks in something digestible like Symfony 2 Console Command and run them through PHP Process Manager
>For example, there is a web page, information for which is downloaded and parsed from several sources. It is logical to parallelize these processes.
It is most logical to run such tasks in the form of cli scripts. Accordingly, the task of parallelization is solved automatically by running N different scripts.
If you need to do everything from one script, then it is most convenient to use fork. Although there will be difficulties with data synchronization.
If, say, a user's visit to a page should initiate background processes (say, a user's response to a forum topic, generating notifications by e-mail), then it is convenient to send a task to gearman. And a demon will spin separately, which will take tasks from the gearman and work them out in a separate thread.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question