Running a php server in Phing

I want to run a task in Phing where I first run the PHP server and then run a PHP Unit test.

This is what I have so far:

<target name="test">
    <!-- Run the PHP server -->
    <exec executable="php">
        <arg line="-S localhost:81 server.php"/>

    <!-- Run my tests -->
    <exec executable="${phpunit.bin}" dir="${test.dir}" passthru="true" returnProperty="test.result">
        <arg line="IntegrationTests"/>

    <!-- Check if succeeded -->
    <condition property="test.succeeded">
        <equals arg1="${test.result}" arg2="0"/>

    <fail unless="test.succeeded" message="Unit Tests Failed"/>

The issue is that Phing hangs after creating the PHP server.

The issue is solved by adding the spawn property like so:

<exec executable="php" spawn="true">

This works as expected, except that the process never actually exits even after Phing exits. In other words, the PHP server is still running long after the Phing has completed it's tasks.

Therefore my question is how to properly run a php server in the background in Phing?


phing's ExecTask does not tell you the process ID, so you can't simply do a kill $pid.

Doing a killall php will kill phing itself, too :)

The best option (still a hack) is probably to pgrep for php -S localhost and kill that process:

<exec command="pkill -f 'php -S localhost:81'"/>

But you have to do that in every case, even if the build fails - so add that line before checking the succeeded property.

Need Your Help

JQuery plugin initialization on browser back button for Turbolinks Rails 5

ruby-on-rails ruby-on-rails-5 turbolinks turbolinks-5

Whats a better solution for initializing jquery plugins on browser back button that aren't just transforming elements when using turbolinks in Rails 5 like masterslider (photo gallery) or slick (ca...

FLOW3: initialization of multi databases

php database doctrine typo3-flow

I want to prepare two database connection, because in the first one are the stuff for the Website (e. g. Blogs, posts, etc.) and in the other one are the account data.