C.43 ParallelTask
Prev | Appendix C. Optional tasks | Next

## C.43 ParallelTask

Executes nested tasks in parallel.

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

- Taking advantage of available processing resources to execute external programs simultaneously.

- Testing servers, where the server can be run in one thread and the test harness is run in another thread.

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.51: Attributes

Name | Type | Description | Default | Required
--- | --- | --- | --- | ---
`threadCount` | `Integer` | Maximum number of threads / processes to use. | n/a | No

### C.43.1 Example

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

Prev | Up | Next
C.42 ManifestTask | Home | C.44 PatchTask