在 Apache 启动/重启(Windows Server)的后台运行 PHP 脚本 [英] Run PHP script in background on Apache start/restart(Windows Server)

查看:37
本文介绍了在 Apache 启动/重启(Windows Server)的后台运行 PHP 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照本手册中的说明在 Windows Server 2008 上安装了带有 PHP 5.4 的 Apache 2.4:Apache 安装手册.Apache 现在作为服务运行.

I've installed Apache 2.4 with PHP 5.4 on Windows Server 2008 following instructions from this manual: Apache installing manual. Apache runs as a service now.

我的应用程序需要一个 php websocket 脚本才能在后台运行.我正在手动运行它:

My application requires a php websocket script to run in the background. I'm running it manually with:

php myscript.php

问题是:有没有办法在系统(apache)重启时自动启动后台脚本?

The question is: Is there a way to start a background script automatically on system(apache) restart?

我发现了以下主题,但我不知道在哪里可以找到适用于 Windows 的 apache 启动脚本.

I found the following topic, but I didn't know where I could find an apache startup script for Windows.

任何帮助都会非常有用.

Any help will be much appriciated.

推荐答案

我想出了一个解决方案 :)

  • 创建一个指向 Apache 目录的环境变量

    I come up with a solution :)

  • Create an environment variable pointing to your Apache directory

    APACHE_HOME = C:/PATH/TO_APACHE
    

  • 重命名 %APACHE_HOME%\bin\httpd.exe%APACHE_HOME%\bin\httpdVendor.exe
  • 创建一个批处理文件并输入以下代码:

  • Rename %APACHE_HOME%\bin\httpd.exe to %APACHE_HOME%\bin\httpdVendor.exe
  • Create a batch file and put the following code :

    php myscript.php
    %APACHE_HOME%\bin\httpdVendor.exe -k runservice
    exit 0
    

  • 下载/安装免费软件BatToExeConverter(下一个,下一个,...)
  • 打开已安装的转换器并打开您新创建的批处理文件
  • 点击按钮Build EXE(让默认配置)
  • 保存文件:%APACHE_HOME%\bin\httpd.exe
  • 启动你的Apache服务器
  • Download/Install the free software BatToExeConverter (next, next, ...)
  • Open the installed converter and open your freshly created batch file
  • Click on the button Build EXE (let the default configuration)
  • Save the file : %APACHE_HOME%\bin\httpd.exe
  • Start your Apache Server
  • 测试:Windows 7、Apache 2.4、Advanced Bat to Exe Converter 2.92

    Tested on : Windows 7, Apache 2.4, Advanced Bat to Exe Converter 2.92

    这篇关于在 Apache 启动/重启(Windows Server)的后台运行 PHP 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆