C.61 ParallelTask

Executes nested tasks in parallel.

Parallel tasks have a number of uses in a Phing build file including:

Any valid Phing task may be embedded within a parallel task, including other parallel tasks.

While the tasks within the parallel task are being run, the main thread will be blocked waiting for all the child threads to complete. If one of the tasks within the parallel task fails, the remaining tasks will continue to run until all tasks have completed. In this situation, the parallel task will also fail.

The threadCount attribute can be used to place a maximum number of available threads for the execution. When not present the value is based on the number of processors present. When present then the maximum number of concurrently executing tasks will not exceed the number of threads specified. Furthermore, each task will be started in the order they are given. But no guarantee is made as to the speed of execution or the order of completion of the tasks, only that each will be started before the next.

Warning

This task is highly experimental, and will only work on *nix machines that have the PHP pcntl extension installed.

Table C.72: Attributes

NameTypeDescriptionDefaultRequired
threadCountIntegerMaximum number of threads / processes to use.n/aNo

C.61.1 Example

<parallel threadCount="4">
                <echo>Job 1</echo>
                <echo>Job 2</echo>
                <echo>Job 3</echo>
                <echo>Job 4</echo>
                </parallel>