windows 下 php 如何通过命令操作符调用 php-cgi 程序

windows 下 php 如何通过命令操作符调用 php-cgi 程序


windows 10 环境下调用 powershell ,而不是 cmd 命令提示符进行操作。

Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能。
它引入了许多非常有用的新概念,从而进一步扩展了您在 Windows 命令提示符和 Windows Script Host 环境中获得的知识和创建的脚本。

找到并进入你安装 php 的文件夹。本人 php 位于 E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts ,你可能已经看出来了,我这里使用的是 phpStudy 2018 版本,这里使用集成环境来测试。

使用 php-cgi.exe -h 来获取 php-cgi 命令操作符的提示:

PS E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts> .\php-cgi.exe -h
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
       php <file> [args...]
  -a               Run interactively
  -b <address:port>|<port> Bind Path for external FASTCGI Server mode
  -C               Do not chdir to the script's directory
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse <file>.  Implies `-q'
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -q               Quiet-mode.  Suppress HTTP Header output.
  -s               Display colour syntax highlighted source.
  -v               Version number
  -w               Display source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.
  -T <count>       Measure execution time of script repeated <count> times.

举个例子,你可能想要让 php-cgi 监听除了默认的 9000 端口之外,还需要让其再监听一个 9001 端口,以便在本地服务器模拟两套进程互通的监听。具体例子请查看我的另一篇:windows 下 nginx 服务器 php 本地开发时通过 curl 请求本地另一个 url 卡死问题

先查看本地 php-cgi 启动了几个,使用 ps | findstr "php-cgi" ,如下,默认一个 9000 端口:

PS E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts> ps | findstr "php-cgi"
    154      17    16292      16116       0.22  30928   1 php-cgi
PS E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts> # 查看 9000 端口
PS E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts> netstat -ano|findstr "9000"
  TCP    127.0.0.1:9000         0.0.0.0:0              LISTENING       28204

开启 9001 端口的另一个 php-cgi 进程:

PS E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts> .\php-cgi.exe -b 127.0.0.1:9001 -c E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts\php.ini

请注意,这里是临时开启另一个 php-cgi 进程,该 powershell 窗口不能关闭,否则将会结束该进程。或者服务器以及 php 重启后,将会返回默认只有一个 9000 端口常驻的进程,如果要永久启动多个进程,需要修改文件。

再重新查看进程信息:

PS E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts> ps | findstr "php-cgi"
    158      17    18584      17380       0.63  25968   1 php-cgi
    173      18    19892      20840       1.22  28204   1 php-cgi
PS E:\PhpStudy20180211\PHPTutorial\php\php-7.1.13-nts> netstat -ano|findstr "9001"
  TCP    127.0.0.1:9001         0.0.0.0:0              LISTENING       25968

可以看到,已经成功启动。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值