php使用winsw 实现windows上守护进程(win10测试可以)
github:
仓库地址: https://github.com/kohsuke/winsw
下载地址: https://github.com/kohsuke/wi...
步骤:
1先到 https://github.com/kohsuke/winsw/releases 下载对应文件,如果没有特殊要求只为实现守护进程只需要下载 sample-minimal.xml 与 WinSW.NET2.exe 或 WinSW.NET4.exe。
2.在桌面新建一个文件夹(在哪里新建都可以)叫做 phpserver(名字英文,与要命名的服务名称相同,不能与已有的服务名称冲突)
服务名称=
文件夹示例:(文件夹初始只有自己下载的exe与配置文件,需要更名为与要创建的服务名称相同的名字。其他文件是我运行之后生成的)
3.修改配置文件
<!-- Copyright (c) 2016 Oleg Nenashev and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> <!-- This is an example of a minimal Windows Service Wrapper configuration, which includes only mandatory options. This configuration file should be placed near the WinSW executable, the name should be the same. E.g. for myapp.exe the configuration file name should be myapp.xml You can find more information about the configuration options here: https://github.com/kohsuke/winsw/blob/master/doc/xmlConfigFile.md Full example: https://github.com/kohsuke/winsw/blob/master/examples/sample-allOptions.xml --> <service> <!--服务ID 要唯一--> <id>phpservice</id> <!-- 服务名字 --> <name>phpservice</name> <!--服务描述 --> <description>test php service </description> <!-- 要运行的文件 --> <executable>D:\PhpStudy\php\php-7.4.1-nts\php.exe</executable> <!-- 要执行的命令 --> <arguments>D:\PhpStudy\WWW\index.php</arguments> </service>
4.执行命令
// 安装服务 phpservice.exe install // 启动服务 phpservice.exe stop // 停止服务 phpservice.exe start // 重启服务(修改配置文件后要重启生效) phpservice.exe restart // 删除服务 phpservice.exe uninstall
5.服务设置 (当服务崩溃的时候进行重启)
查看服务已正常运行:
设置服务中断后的操作:
主要参考
https://segmentfault.com/a/1190000019520072
博 主 :夏秋初
地 址 :https://www.cnblogs.com/xiaqiuchu/p/12535141.html
如果对你有帮助,可以点一下 推荐 或者 关注 吗?会让我的分享变得更有动力~
转载时请带上原文链接,谢谢。
地 址 :https://www.cnblogs.com/xiaqiuchu/p/12535141.html
如果对你有帮助,可以点一下 推荐 或者 关注 吗?会让我的分享变得更有动力~
转载时请带上原文链接,谢谢。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义