ds261634878 2017-03-20 20:08
浏览 28
已采纳

检测内置PHP服务器的拆解

Is there a way to detect if a running built-in PHP server has been stopped? Either by hitting Ctrl-C or just by closing the terminal window.

I'm using it for a development environment and would like to clean up some files on teardown.

  • 写回答

2条回答 默认 最新

  • dqmdlo9674 2017-03-20 20:36
    关注

    well, i don't know if there are exist in the php built-in server feature to do so,

    but as a work around you may accomplish this using terminal,

    using the ; symbol which is used to separate two commands and in executing the second command after the first command finishes it's execution.

    for example this script will add shut down line to the file status.txt only when you hit CTRL+C -finishing the first command- :

    php -S localhost:8000 ; echo "shut down" >> status.txt
    

    you may create a new php/bash script or whatever to execute specific tasks and execute it after exiting the server -after hitting CTRL+C

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化