R
R
Rhaps1072013-02-18 20:59:20
PHP
Rhaps107, 2013-02-18 20:59:20

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

8 answer(s)
S
stan_jeremy, 2013-02-18
@stan_jeremy

if you really just need to parse, then you can use php.net/manual/ru/function.curl-multi-exec.php ?

S
Skpd, 2013-02-18
@Skpd

Gearman

V
Vyacheslav Slinko, 2013-02-18
@KeepYourMind

github.com/reactphp/react/blob/master/examples/parallel-download.php

V
Vyacheslav Slinko, 2013-02-18
@KeepYourMind

reactphp.org

Z
zizop, 2013-02-19
@zizop

As an option, wrap tasks in something digestible like Symfony 2 Console Command and run them through PHP Process Manager

B
Bal, 2013-02-21
@Bal

>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.

S
Sergey Cherepanov, 2013-02-18
@fear86

Maybe also php.net/manual/ru/function.pcntl-fork.php

I
Ivan, 2013-02-19
@Praeses

If it's quite simple. then with the nohup command we completely separate the process into execution.
And we set some conditions for processing different data (so that there is no layering in processing).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question