php / php/php-src

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

Open
#20,459 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.2k
Avg merge
2d 15h
Merged PRs (30d)
103

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided CLI command, PHP 8.4.12, and Debian bookworm environment, then reproduce the memory growth while tracing the application's Dir::read call. Isolate whether the behavior comes from PHP or the application code and document a minimal reproducible case and expected memory behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
debian, linux, php
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.