Skip to content

[Performance] MasterFingerprint::readUidForPid() reads whole /proc/{pid}/status — bounded fread + strpos would reduce the read #803

Description

@s2x

Description

Found during the #567 cycle. MasterFingerprint::readUidForPid() (src/MasterFingerprint.php:114-135) reads the entire /proc/{pid}/status file and runs a multiline regex (preg_match('/^Uid:\s+(\d+)/m', ...)). The Uid: field is near the head of the file, so a bounded fread() of the first ~256 bytes plus strpos() avoids the full read and PCRE. UID cannot be read from /proc/{pid}/stat, so the file itself cannot be avoided — only the read size.

Reachable from ProcessInspector::readLinuxProcessSnapshot() (src/ProcessInspector.php:519) and MasterFingerprint::capture().

Where

  • src/MasterFingerprint.php:114-135

Suggested fix

Bounded fread() of the head of /proc/{pid}/status + strpos()/parse, replacing the full file_get_contents() + /m regex.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestminorMinor priority - code quality

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions