PHP 8.2 FPM Leaks processes on pcntl_fork

未关闭
#12,155 13 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
php
领域
backend

调研方向

从提供的 Drupal 10 index.php 复现代码开始,重点关注 pcntl_fork() 调用和 PHP-FPM 进程的行为。使用 Ubuntu 16.04 上的 PHP 8.2.10 复现,并与 PHP 7.4 进行比较。当 fork 出的进程在 sleep 后被清理,而不是脱离并继续存在于 FPM master 进程下时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Extension: pcntl Feature Status: Needs Triage
Description

OS: xenial
PHP tested: 8.2.7, 8.2.10

The following drupal 10 index.php:

<?php

/**
 * @file
 * The PHP page that serves all page requests on a Drupal installation.
 *
 * All Drupal code is released under the GNU General Public License.
 * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
 */

use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

$kernel = new DrupalKernel('prod', $autoloader);

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$pid = pcntl_fork();
    if ( $pid !== 0  ) {
        // we are the parent process
        return;
    }
    sleep(10);

$kernel->terminate($request, $response);

After doing ~5 requests to the site, results in the following sub-processes to the FPM master:

root     15873  0.0  0.8 464188 17200 ?        Ss   13:08   0:00 php-fpm: master process (/var/www/site-fpm/drush12test.prod/php-fpm-8.2.conf)
drush12+ 16518  0.7  1.4 466300 29860 ?        S    13:11   0:00  \_ php-fpm: pool drush12test
drush12+ 16557  0.0  0.6 466300 13068 ?        S    13:11   0:00      \_ php-fpm: pool drush12test
drush12+ 16559  0.0  0.6 466300 12640 ?        S    13:11   0:00      \_ php-fpm: pool drush12test
drush12+ 16561  0.0  0.6 466300 12640 ?        S    13:11   0:00      \_ php-fpm: pool drush12test
drush12+ 16563  0.0  0.6 466300 12640 ?        S    13:11   0:00      \_ php-fpm: pool drush12test

But then after a few seconds, when it should clean them up, they will instead detach and linger around:

root     15873  0.0  0.8 464188 17188 ?        Ss   13:08   0:00 php-fpm: master process (/var/www/site-fpm/drush12test.prod/php-fpm-8.2.conf)
drush12+ 16557  0.0  1.1 464252 23364 ?        S    13:11   0:00 php-fpm: pool drush12test
drush12+ 16559  0.0  1.1 464252 23028 ?        S    13:11   0:00 php-fpm: pool drush12test
drush12+ 16561  0.0  1.1 464252 23028 ?        S    13:11   0:00 php-fpm: pool drush12test
drush12+ 16563  0.0  1.1 466300 23432 ?        S    13:11   0:00 php-fpm: pool drush12test

The same doesn't happen with PHP 7.4. In that case the processes get cleaned up properly.

PHP Version

PHP 8.2.10

Operating System

Ubuntu 16.04

主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 15 小时
30 天内合并 PR
103

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。