AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 805563
Accepted
Doua Beri
Doua Beri
Asked: 2016-09-28 02:51:50 +0800 CST2016-09-28 02:51:50 +0800 CST 2016-09-28 02:51:50 +0800 CST

windows在同一个bat的后台启动nginx和php-fpm

  • 772

我正在尝试在 Windows 10 上创建一个 bat 文件以在后台启动 nginx 和 php-fpm。目前我可以这样做,但命令窗口(黑色窗口)仍然打开。如果我关闭窗口,php-fpm 也会终止。

这是我在 start.bat 中添加的内容

@ECHO OFF
cd D:\servers\nginx-1.10.1\
echo Starting Nginx...
start /B cmd /K "D:\servers\nginx-1.10.1\nginx.exe"
echo Start Php-cgi...
start /B cmd /K "D:\servers\php-5.6.26\php-cgi.exe -b 127.0.0.1:9000 -c D:\servers\php-5.6.26\php.ini"
EXIT

这是打印在黑色窗口上的内容:

Starting Nginx...
Start Php-cgi...

我希望窗口自动关闭,但保持进程(nginx 和 php-fpm)运行。

nginx batch php-fpm batch-processing
  • 3 3 个回答
  • 5921 Views

3 个回答

  • Voted
  1. Best Answer
    user3430227
    2017-05-24T01:30:16+08:002017-05-24T01:30:16+08:00

    php-cgi 锁定窗口。尝试 nginx 家伙在他们的页面上给出的解决方案。 Windows 上的 PHP-FastCGI

    • 3
  2. user4817819
    2018-02-16T09:23:07+08:002018-02-16T09:23:07+08:00

    您可以隐藏控制台窗口作为解决此问题的方法之一。使用hidcon等 CLI 实用程序很容易。对于我的项目,我使用这个脚本:start-server.cmd

    @Echo Off
    :: Portable nginx+php5+mysql for Windows
    :: Inquisitor, 2016-2018
    CD /D "%~dp0"
    
    :: Settings
    Set LogFile=.\%~n0.log
    Set TimestampFormat=[%%Date%% %%Time:~,8%%]
    Set WatcherTimeout=10
    
    If "%~1"=="" (
        Start "" "%~dp0tools\hidcon" %~nx0 restart_hidden
        Call Echo.>>"%LogFile%"
        Call :Log Loader started
        Exit
    )
    
    
    Set Path=%~dp0tools;%~dp0nginx;%~dp0php-fpm;%~dp0mysql\bin;%Path%
    ::  ImageMagick 6.9.3-3
    rem Set Path=%Path%;%~dp0modules\imagick6
    ::  ImageMagick 7.0.5.10
    rem Set Path=%Path%;%~dp0modules\imagick7
    ::  FFMpeg 3.3.1
    Set Path=%Path%;%~dp0modules\ffmpeg
    
    Set Temp=%~dp0\tmp
    
    
    
    :: MySQL
    Call :Log Starting MySQL...
    :start-mysql
    PushD .\mysql\bin
    Start mysqld --defaults-file=my.ini --standalone
    PopD
    If "%1"=="restart" (
        Call :Log MySQL crashed, restarting
        Exit /B
    )
    
    :: PHP
    Call :Log Starting PHP-FPM...
    :start-php
    PushD .\php-fpm
    Start hidcon php-cgi -b 127.0.0.1:9123 -c ".\php.ini"
    PopD
    If "%1"=="restart" (
        Call :Log PHP-FPM crashed, restarting
        Exit /B
    )
    
    :: nginx
    Call :Log Starting NginX...
    :start-nginx
    PushD .\nginx
    Start nginx
    PopD
    If "%1"=="restart" (
        Call :Log NginX crashed, restarting
        Exit /B
    )
    
    
    
    TaskKill /F /IM "hidcon.exe"
    
    For %%A In ("mysqld.exe", "php-cgi.exe", "nginx.exe") Do (
        wmic process where name="%%~A" CALL setpriority "high priority"
    )
    
    
    
    Set LockFile=.\.%~n0.lock
    Echo.>"%LockFile%"
    
    :Watcher
    Ping -n %WatcherTimeout% 127.0.0.1>nul 2>nul
    TaskList /FI "imagename EQ php-cgi.exe" /FO:CSV|FindStr /I /C:"php-cgi.exe">nul||Call :start-php restart
    If Not Exist "%LockFile%" (
        Call :Log Lockfile not found, starting shutdown process
    
        PushD .\nginx
        nginx -s stop
        PopD
    
        mysqladmin -u root -pPCIIctvYUijcfNLR shutdown
    
        TaskKill /F /T /IM php-cgi.exe
    
        Call :Log Loader stopped
        Exit
    )
    GoTo :Watcher
    
    :Log
        Call Echo %TimestampFormat% %*>>"%LogFile%"
    Exit /B
    

    和简单的 stop-server.cmd:

    @Echo Off
    Del "%~dp0.loader.lock" 2>nul
    
    • 0
  3. user582775
    2020-07-13T00:16:39+08:002020-07-13T00:16:39+08:00
    RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9001
    

    https://github.com/wenshui2008/RunHiddenConsole

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve