php / php/php-src

Recursive search on a linux system (1 thread) from root including subdirectories causes 8.4 GB Ram and counting

未关闭
#20,459 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

The following code:

<?php
/**
     * @throws DirectoryCreateException
     * @throws Exception
     */
    public function search($flags, $options): void
    {
        $object = $this->object();
        $data = new Data($object->data());
        if(!property_exists($options, 'name')){
            throw new Exception('Option -name not set');
        }
        if(!property_exists($options, 'directory')){
            throw new Exception('Option -directory not set');
        }
        $dir = new Dir();
        $list = $dir->read($options->directory, true);
        foreach($list as $file){
            if($file->name === $options->name){
                breakpoint('match');
            }
        }
        breakpoint($list);
    }

Resulted in this output:

15625 root      20   0 9139760   8.5g   2304 R  99.7  55.0  15:11.97 php
15625 root      20   0   13.3g  13.0g   2304 R 100.0  83.9  24:48.36 php

But I expected this output instead:

15625 root      20   0 9139760   1.5g   2304 R  99.7  3.0  15:11.97 php

What i meant is this:

I keep a list of all files on the system and searches for a match.
I can create a search from root directory and go 1 subdirectory at a time but my opinion is that searching on a root device should work like a charm without complicating stuff too much...

PHP Version
PHP 8.4.12 (cli) (built: Sep  7 2025 14:06:59) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.12, Copyright (c), by Zend Technologies
Operating System

Debian bookworm
CLI:
app raxon/basic file search -directory=/ -name=Snow.js

No response

贡献指南

打开贡献指南

从这里开始

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

调研方向

先使用提供的 CLI 命令、PHP 8.4.12 和 Debian bookworm 环境,然后在跟踪应用程序的 Dir::read 调用时重现内存增长。确定该行为是由 PHP 还是应用程序代码导致的,并记录一个最小可复现案例以及预期的内存行为。

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

评估

技术栈
debian, linux, php
领域
cli, operating-systems
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

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