我想在Phing中运行一个任务,我首先运行PHP服务器,然后运行PHP单元测试。
这是我到目前为止所做的:
<target name="test">
<!-- Run the PHP server -->
<exec executable="php">
<arg line="-S localhost:81 server.php"/>
</exec>
<!-- Run my tests -->
<exec executable="${phpunit.bin}" dir="${test.dir}" passthru="true" returnProperty="test.result">
<arg line="IntegrationTests"/>
</exec>
<!-- Check if succeeded -->
<condition property="test.succeeded">
<equals arg1="${test.result}" arg2="0"/>
</condition>
<fail unless="test.succeeded" message="Unit Tests Failed"/>
</target>
问题是Phing在创建PHP服务器后挂起。
通过添加如下所示的spawn属性来解决该问题:
<exec executable="php" spawn="true">
这可以按预期工作,除了即使Phing退出后该过程也从未实际退出。换句话说,在Phing完成任务后,PHP服务器仍然运行很久。
因此我的问题是如何在Phing的后台正确运行php服务器?
答案 0 :(得分:1)
phing's ExecTask没有告诉您进程ID,因此您不能简单地执行kill $pid
。
做killall php
也会杀死phing本身:)
pgrep
的最佳选择(仍然是黑客)可能会php -S localhost
并杀死该进程:
<exec command="pkill -f 'php -S localhost:81'"/>
但是你必须在每种情况下都这样做,即使构建失败 - 所以在检查succeeded
属性之前添加该行。