win平台利用winsw将php-cgi作为系统服务,支持服务的正常启动/停止/重启

首先,需要有winsw, 在GitHub 搜索winsw,点击release 跳转到下载页面选择版本进行下载或点击此链接 Releases · winsw/winsw (github.com)

其次,将winsw 复制到php目录,重命名为 phpcgi-service.exe 并增加配置文件phpcgi-service.xmlstop-cgi.bat ,其中 phpcgi-service.xml 的内容为

<service>
    <id>phpcgi8.3.9</id>
    <name>phpcgi8.3.9</name>
    <description>phpcgi 服务</description>
    <logpath>%BASE%\logs</logpath>
    <logmode>roll</logmode>
    <executable>php-cgi.exe</executable>
    <arguments> -b 127.0.0.1:9000 %BASE%\php.ini</arguments>
    <stopexecutable>stop-cgi.bat</stopexecutable>
</service>

其中,stop-cgi.bat 的代码为:

taskkill /f /im php-cgi.exe

然后,安装服务,使用管理员身份运行cmd,切换到当前目录,运行如下命令即可完成服务的安装,然后就能到系统服务里进行 启动/停止/重启服务 操作了,注意,修改winsw的xml是立即生效的,不需要重新卸载服务在安装

phpcgi-service.exe install

ps: phpcgi-service.xml 中的 %BASE% 为 winsw 可以识别的内置变量,代表winsw.exe 所在的目录,github上的帮助文档不是太全,特此说明

 

posted @ 2024-07-28 21:53  漫漫人生路总会错几步  阅读(1)  评论(0编辑  收藏  举报