doutang7383 2016-09-22 11:15
浏览 28

在Phing中运行php服务器

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"/>
    </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>

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?

  • 写回答

1条回答 默认 最新

  • douxun4924 2016-09-27 11:01
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)