How to start the PHP server, run PHPUnit and stop the PHP server in Ant?

advertisements

I have a target like this in Ant

<target name="test">
    <exec executable="php" failonerror="true">
        <arg value="-S"/>
        <arg value="localhost:80"/>
        <arg value="-t"/>
        <arg value="web"/>
    </exec>
    <exec executable="phpunit" failonerror="true">
        <arg value="tests"/>
    </exec>
</target>

The problem is when I run this, the target will block because of the PHP build-in server. How do I start the PHP server, and then run the PHP unit, and then stop the server when the PHP unit completes (either success or failed)?


If you want Ant to spawn the php process, you can set spawn="true" in the task invocation:

<exec executable="php" failonerror="true" spawn="true">
    <arg value="-S"/>
    <arg value="localhost:80"/>
    <arg value="-t"/>
    <arg value="web"/>
</exec>

A note on its usage from the documentation though:

If you spawn a command, its output will not be logged by ant. The input, output, error, and result property settings are not active when spawning a process.