【问题标题】:Running a php server in Phing在 Phing 中运行 php 服务器
【发布时间】:2016-09-22 11:15:52
【问题描述】:

我想在 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 属性解决了这个问题:

&lt;exec executable="php" spawn="true"&gt;

这按预期工作,只是即使在 Phing 退出后进程也不会真正退出。换句话说,PHP 服务器在 Phing 完成它的任务后仍然运行很长时间。

因此我的问题是如何在 Phing 的后台正确运行 php 服务器?

【问题讨论】:

    标签: php phing


    【解决方案1】:

    phing's ExecTask 不会告诉你进程 ID,所以你不能简单地做一个kill $pid

    执行killall php 也会杀死 phing 本身 :)

    最好的选择(仍然是 hack)可能是 pgrepphp -S localhost 并终止该进程:

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

    但你必须在任何情况下都这样做,即使构建失败 - 所以在检查 succeeded 属性之前添加该行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多