适用于 Windows 的 php-fpm?

发布于 2024-10-09 07:33:37 字数 193 浏览 3 评论 0原文

PHP-FPM 的主页 http://php-fpm.org/ 声明它是 PHP 的一部分,因为 PHP 5.3.3.现在,我想知道,当我从 php.net 下载最新的 PHP 二进制文件时,其中没有 php-fpm。我怎样才能得到它?它甚至适用于 Windows 吗?

The PHP-FPM's homepage http://php-fpm.org/ states that it is part of PHP since PHP 5.3.3. Now, I was wondering, when I download the newest PHP binaries from php.net, there is no php-fpm in it. How do I get it? Is it even available for Windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

岁月苍老的讽刺 2024-10-16 07:33:37

以下是如何在 Windows 上设置 php-fpm:

  1. http://windows.php.net/download/ 下载 .zip 文件。 .zip 文件应该是 VC9,其中包含 FastCGI 文件 (php-cgi.exe)。不要下载 VC6,也不要下载 .msi 文件,因为它要求您已经安装 IIS 才能安装 php-fpm。该 zip 文件包含 php-cgi.exe,这是 php-fpm 所需的文件。我从这里下载了一个稍旧的版本 php-5.3.10-Win32-VC9-x86.zip http:// windows.php.net/downloads/releases/archives/ 因为我想匹配在我的生产服务器上运行的版本。

  2. 解压文件,例如解压到C:\php-5.3.10-Win32-VC9-x86

  3. < p>根据需要编辑 php.ini 文件。我做了什么:

    # nginx 安全设置
    cgi.fix_pathinfo=0
    
    extension_dir = "C:\php-5.3.10-Win32-VC9-x86\ext"
    

    通过取消注释来启用以下模块:

    扩展=php_curl.dll
    扩展名=php_mbstring.dll
    扩展名=php_mysqli.dll
    
  4. 在某处创建一个 .bat 文件,例如在 webserver 目录或 PHP 目录中的 start-php-fcgi.bat:

    <前><代码>@ECHO 关闭
    ECHO 启动 PHP FastCGI...
    设置 PATH=C:\php-5.3.10-Win32-VC9-x86;%PATH%
    C:\php-5.3.10-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9123 -c C:\php-5.3.10-Win32-VC9-x86\php.ini

  5. 双击.bat 文件启动php-fpm。运行时将弹出一个窗口并保持打开状态。这有点烦人,但只是还没有考虑将其设置为服务。

  6. 配置您的网络服务器。如果您希望将其与 nginx 一起使用,这里是 127.0.0.1:9123 的配置示例:

    位置 ~ \.php$ {
        fastcgi_pass 127.0.0.1:9123;
        fastcgi_index索引.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        包括 fastcgi_params;
    }
    

Here how to setup php-fpm on Windows:

  1. Download the .zip file from http://windows.php.net/download/. The .zip file should be VC9 which has the FastCGI file (php-cgi.exe). Don't download VC6, and don't download the .msi file because it requires that you have IIS setup already in order to install php-fpm. The zip file contains the php-cgi.exe which is what you need for php-fpm. I downloaded a slightly older version, php-5.3.10-Win32-VC9-x86.zip, from here http://windows.php.net/downloads/releases/archives/ because I wanted to match the version running on my production server.

  2. Unzip the file, e.g. unzip into C:\php-5.3.10-Win32-VC9-x86

  3. Edit the php.ini file as needed. What I did:

    # nginx security setting
    cgi.fix_pathinfo=0
    
    extension_dir = "C:\php-5.3.10-Win32-VC9-x86\ext"
    

    enable the following modules by uncommenting them:

    extension=php_curl.dll
    extension=php_mbstring.dll
    extension=php_mysqli.dll
    
  4. Create a .bat file somewhere, e.g. start-php-fcgi.bat in webserver directory or in the PHP directory:

    @ECHO OFF
    ECHO Starting PHP FastCGI...
    set PATH=C:\php-5.3.10-Win32-VC9-x86;%PATH%
    C:\php-5.3.10-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9123 -c C:\php-5.3.10-Win32-VC9-x86\php.ini
    
  5. Double click the .bat file to start php-fpm. A window will popup and stay open while its running. Its kind of annoying, but just haven't looked into setting it up as service yet.

  6. Configure your webserver. If you wish to use it with nginx, here a config sample for 127.0.0.1:9123:

    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9123;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include         fastcgi_params;
    }
    
有深☉意 2024-10-16 07:33:37

尽管这篇文章很旧,但我必须在这里权衡一下,因为这里发布的不是 PHP-FPM,而是使用 Fast-CGI 运行 PHP。

是的,PHP-FPM 代表 PHP-FastCGI 进程管理器,因此实现了 FastCGI,但您忘记了 FPM 远不止于此,因为它包含不由 Web 服务器管理的进程管理功能。

在 *nix 系统上,PHP-FPM 有一个单独的进程来管理 PHP 子进程,并有详细的配置来指定如何管理这些进程。有关这些功能的详细信息,请阅读此处

在 Windows 上启动 CGI 进程是不一样的事物。它不会产生工作进程或动态扩展它们或允许多线程。

目前还没有适用于 Windows 的 PHP-FPM。
http://php.net/manual/en/install.fpm.php#121725

但是,正如建议的,如果您愿意,您可以启动 CGI 进程。

Old as this post is I have to weigh in here because what has been posted here is not PHP-FPM, it's running PHP using Fast-CGI.

Yes PHP-FPM stands for PHP-FastCGI Process Manager and so implements FastCGI but you are forgetting that FPM is much more than that as it contains process management features that are not managed by the webserver.

On *nix systems PHP-FPM has a separate process that manages the PHP child processes and has a detailed configuration to specify how these processes are managed. For details on these features read here

Launching a CGI process on windows is not the same thing. It does not spaw worker processes or dynamically scale them or allow multi-threading.

There is no PHP-FPM for windows yet.
http://php.net/manual/en/install.fpm.php#121725

However as suggested, you may launch a CGI process if you wish.

久随 2024-10-16 07:33:37

艾伦的回答是一个很好的开始。但是,对于 Apache 2.4 及更高版本,您不需要将 PHP-FPM 作为单独的服务运行,您可以使用 mod_fcgid 来处理 Apache 中的所有内容。

下面是一个示例配置:

LoadModule fcgid_module modules/mod_fcgid.so

FcgidInitialEnv PHPRC "c:/php"
FcgidInitialEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 500

<Files ~ "\.php$">
  AddHandler fcgid-script .php
  FcgidWrapper c:/php/php-cgi.exe .php
</Files> 

注意,这是基于 Apache Lounge 中的帖子 。尽管它很有帮助,但他们的版本在 c:/php/php-cgi.exe 周围有引号,如果你这样做,它不会启动 php-cgi.exe,至少在 Windows Server 2012 上,并且你会得到 HTTP 500。我花了几天痛苦的时间才弄清楚这一点。

Alan's answer is a great start. However, for Apache 2.4 and later you do not need to run PHP-FPM as a separate service, you can use mod_fcgid to handle everything within Apache.

Here is an example configuration:

LoadModule fcgid_module modules/mod_fcgid.so

FcgidInitialEnv PHPRC "c:/php"
FcgidInitialEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 500

<Files ~ "\.php$">
  AddHandler fcgid-script .php
  FcgidWrapper c:/php/php-cgi.exe .php
</Files> 

Note, this is based on a post in Apache Lounge. As helpful as it was, their version had quotes around c:/php/php-cgi.exe and if you do that it WILL NOT START php-cgi.exe, at least on Windows Server 2012, and you get HTTP 500. Took me a painful few days to figure that out.

反目相谮 2024-10-16 07:33:37

从 PHP v5.3.3 开始,FPM Server-API [SAPI] 支持已集成到核心 PHP 中。这意味着,您可以获取 PHP 的源代码并使用 FPM-SAPI [使用 --enable-fpm 配置参数] 支持来编译和构建它们,而不是让我们说 Apache SAPI [--enable -apx2]。如 PHP-Wiki 所示,您几乎可以像在 * 中一样构建 PHP nix 系统 - 即配置方面。我建议您首先了解在 *nix 系统中构建 PHP 的细节,甚至尝试自己动手 [通常的 configuremakemake installpattern],然后尝试利用从中获得的经验在Windows环境上进行构建。

除了 --enable-fpm 配置参数之外,还有两个附加参数:--with-fpm-user=USERNAME_HERE--with- fpm-group=USERGROUPNAME_HERE。这两个在 *nix 环境下工作,但在 Windows 下可能不可用。

总的来说,我非常确定您可以使用 Visual Studio IDE 在 Windows 上构建自己的 PHP-FPM 服务器应用程序。截至本文撰写之日,还没有正式的 PHP-FPM 版本。

编辑 1:好吧,我猜我在 Windows 上构建 PHP-FPM 的可能性可能是错误的,因为这个 SAPI 使用 *nix 环境中的 libevent 组件。我猜你必须坚持使用 Cygwin 捆绑安装 毕竟。

Starting PHP v5.3.3, FPM Server-API [SAPI] support has been integrated into core PHP. This means, you can take PHP's source codes and compile and build them with FPM-SAPI [using --enable-fpm configuration parameter] support, instead of let's say Apache SAPI [--enable-apx2]. As shown in PHP-Wiki you can build PHP almost the same way you do in *nix systems - that is, configuration-wise. I would suggest you learn the ins and outs of building PHP in *nix systems first, and even try to do it yourself [usual configure, make and make install pattern], and then try to utilize the experience gained from it to build on Windows environment.

In addition to --enable-fpm configuration parameter, there are two additional parameters as well: --with-fpm-user=USERNAME_HERE and --with-fpm-group=USERGROUPNAME_HERE. These two work in *nix environment, but may not be available in Windows.

Overall, I am pretty sure you can build your own PHP-FPM server app on Windows using Visual Studio IDE. There are no official PHP-FPM builds as of the date of this writing.

EDIT 1: Ok, guess I might be wrong re the possibility of building PHP-FPM on Windows, since this SAPI uses libevent component from *nix environment. Guess you will have to stick with Cygwin-bundled installation after all.

合约呢 2024-10-16 07:33:37

在 Windows 上,当您通过 IIS 运行 PHP 并安装“PHP FastCGI”模块时,您将获得与 PHP-FPM 所解释的类似功能。换句话说,这不是官方的 PHP-FPM 代码库,而只是类似的功能。

其一,IIS 会生成多个 php-cgi.exe 进程(工作进程)。任何进来的 PHP 请求都将被传递给一个工作线程,IIS 将根据服务器资源动态生成更多工作线程。这些设置可在 IIS 上服务器树节点的“快速 CGI”选项下进行配置。

也就是说,我相信 php-cgi.exe 的性能无法与 Apache 服务器相提并论。

您可以在此处查看 IIS 7 的安装过程: https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php -applications-on-iis/using-fastcgi-to-host-php-applications-on-iis

FastCGI 通过提供一种针对许多请求反复重用单个进程的机制来解决 CGI 固有的性能问题。此外,FastCGI 通过提供一组可重用进程并确保每个进程一次仅处理一个请求来保持与非线程安全库的兼容性。

On Windows, when you run PHP with IIS and install the "PHP FastCGI" module, you get similar functionality to what is explained about PHP-FPM. In other words, this is not the official PHP-FPM code base, but just similar functionality.

For one, IIS would spawn multiple php-cgi.exe processes (worker processes). And any PHP requests that come in will be handed down to a worker, IIS will dynamically spawn more workers depending on the server resources. These settings are configurable under the "Fast CGI" options for the server tree node on IIS.

That said, I believe performance-wise the php-cgi.exe is not on par with Apache servers.

You can view the installation procedure for IIS 7 here: https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php-applications-on-iis

FastCGI addresses the performance issues that are inherent in CGI by providing a mechanism to reuse a single process over and over again for many requests. Additionally, FastCGI maintains compatibility with non-thread-safe libraries by providing a pool of reusable processes and ensuring that each process handles only one request at a time.

凉城凉梦凉人心 2024-10-16 07:33:37

PHP-FPM 目前仅适用于 Linux。有一些网站提供了有关如何在 cygwin 下在 Windows 上运行 php-fpm 的教程。您可以尝试这些指南。

PHP-FPM is only available to linux as of now. There are some sites that provides a tutorial on how to get php-fpm to run on windows, under cygwin. You can try those guides.

野の 2024-10-16 07:33:37

PHP-FPM 主要使用 *NIX 特定功能,不太可能移植到 Windows。最后确实没有动力,特别是考虑到 php-cgi 的开发是为了允许 Windows 特定服务将其配置为分叉池。是的,它们有其差异,但不足以推动社区完全重写 PHP-FPM。

请记住,Windows 上的 php-cgi 不仅仅是 CGI 的多个实例,而且使用 Windows 管理的分叉 FastCGI 处理器池,这些处理器使用与 PHP-FPM 相同的体系结构。多个进程完成 PHP 的模块初始化,并从这些进程中维护多个分支(并在需要时重新启动)来处理请求。至少从 PHP3 开始,php-cgi 就不是 CGI。

PHP-FPM uses mainly *NIX specific features and is not likely to ever be ported to Windows. In the end there really isn't the motivation, especially when considering php-cgi was developed to allow Windows specific services to configure it as a fork pool. Yes, they have their differences, but not enough so to push the community into a complete rewrite of PHP-FPM.

Keep in mind that php-cgi on Windows is not just multiple instances of a CGI, but uses a Windows managed pool of forked FastCGI processors which use the same architecture of PHP-FPM. Multiple processes complete the module initialization of PHP, and from these multiple forks are maintained (and restarted when needed) to handle requests. php-cgi hasn't been a CGI since at least as early as PHP3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文