cursorrules / rules
Cursor rule88 starsChanged 13 months agoMITView on GitHub
PHP memory optimisation standards and actionable checks
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository70 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/accessibility-standards.mdcCursor rule
- .cursor/rules/api-standards.mdcCursor rule
- .cursor/rules/behat-ai-guide.mdcCursor rule
- .cursor/rules/behat-steps.mdcCursor rule
- .cursor/rules/build-optimization.mdcCursor rule
- .cursor/rules/code-generation-standards.mdcCursor rule
- .cursor/rules/confluence-editing-standards.mdcCursor rule
- .cursor/rules/cursor-rules.mdcCursor rule
- .cursor/rules/debugging-standards.mdcCursor rule
- .cursor/rules/docker-compose-standards.mdcCursor rule
- .cursor/rules/drupal-authentication-failures.mdcCursor rule
- .cursor/rules/drupal-broken-access-control.mdcCursor rule
- .cursor/rules/drupal-cryptographic-failures.mdcCursor rule
- .cursor/rules/drupal-database-standards.mdcCursor rule
- .cursor/rules/drupal-file-permissions.mdcCursor rule
- .cursor/rules/drupal-injection.mdcCursor rule
- .cursor/rules/drupal-insecure-design.mdcCursor rule
- .cursor/rules/drupal-integrity-failures.mdcCursor rule
- .cursor/rules/drupal-logging-failures.mdcCursor rule
- .cursor/rules/drupal-security-misconfiguration.mdcCursor rule
- .cursor/rules/drupal-ssrf.mdcCursor rule
- .cursor/rules/drupal-vulnerable-components.mdcCursor rule
- .cursor/rules/generic_bash_style.mdcCursor rule
- .cursor/rules/git-commit-standards.mdcCursor rule
- .cursor/rules/github-actions-standards.mdcCursor rule
- .cursor/rules/improve-cursorrules-efficiency.mdcCursor rule
- .cursor/rules/javascript-broken-access-control.mdcCursor rule
- .cursor/rules/javascript-cryptographic-failures.mdcCursor rule
- .cursor/rules/javascript-identification-authentication-failures.mdcCursor rule
- .cursor/rules/javascript-injection.mdcCursor rule
- .cursor/rules/javascript-insecure-design.mdcCursor rule
- .cursor/rules/javascript-performance.mdcCursor rule
- .cursor/rules/javascript-security-logging-monitoring-failures.mdcCursor rule
- .cursor/rules/javascript-security-misconfiguration.mdcCursor rule
- .cursor/rules/javascript-server-side-request-forgery.mdcCursor rule
- .cursor/rules/javascript-software-data-integrity-failures.mdcCursor rule
- .cursor/rules/javascript-standards.mdcCursor rule
- .cursor/rules/javascript-vulnerable-outdated-components.mdcCursor rule
- .cursor/rules/lagoon-docker-compose-standards.mdcCursor rule
- .cursor/rules/lagoon-yml-standards.mdcCursor rule
- .cursor/rules/multi-agent-coordination.mdcCursor rule
- .cursor/rules/new-pull-request.mdcCursor rule
- .cursor/rules/node-dependencies.mdcCursor rule
- .cursor/rules/php-drupal-best-practices.mdcCursor rule
- .cursor/rules/php-drupal-development-standards.mdcCursor rule
- .cursor/rules/project-definition-template.mdcCursor rule
- .cursor/rules/pull-request-changelist-instructions.mdcCursor rule
- .cursor/rules/python-authentication-failures.mdcCursor rule
- .cursor/rules/python-broken-access-control.mdcCursor rule
- .cursor/rules/python-cryptographic-failures.mdcCursor rule
- .cursor/rules/python-injection.mdcCursor rule
- .cursor/rules/python-insecure-design.mdcCursor rule
- .cursor/rules/python-integrity-failures.mdcCursor rule
- .cursor/rules/python-logging-monitoring-failures.mdcCursor rule
- .cursor/rules/python-security-misconfiguration.mdcCursor rule
- .cursor/rules/python-ssrf.mdcCursor rule
- .cursor/rules/python-vulnerable-outdated-components.mdcCursor rule
- .cursor/rules/react-patterns.mdcCursor rule
- The first 60 shown.
The file
We split this php-memory-optimisation.mdc into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 42
Stream database results: Prefer $stmt->fetch(PDO::FETCH_ASSOC) in a while loop or use generators instead of fetchAll().
- Very specific: line 44
Stream files: Use SplFileObject or chunked reads instead of file_get_contents() for large files.
- Very specific: line 45
Minimise array copying: Avoid array_merge() in loops.
- Very specific: line 47
Profile memory: Use memory_get_usage() and tools like Xdebug/Blackfire to spot peaks.
- Distinctive: line 48
OPcache: Ensure OPcache is enabled and sized appropriately in production.
- Very specific: line 74
Consider opcache.interned_strings_buffer and opcache.max_accelerated_files for larger codebases.
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: PHP memory optimisation standards and actionable checks
globs: *.php, *.ini
---
# PHP Memory Optimisation Standards
Guidance and automated checks to reduce peak memory usage in PHP applications. Based on widely accepted practices and the article "PHP Memory Optimization Tips" by Khouloud Haddad.
<rule>
name: php_memory_optimisation
description: Detect memory-heavy patterns and suggest streaming, generators, and better data handling
filters:
- type: file_extension
pattern: "\\.php$"
actions:
- type: enforce
conditions:
# Avoid loading entire DB result sets into memory.
- pattern: "->fetchAll\\("
message: "Avoid fetchAll() on large result sets; iterate with fetch() in a loop or wrap with a generator (yield)."
- pattern: "\\bmysqli_fetch_all\\("
message: "Avoid mysqli_fetch_all() for large queries; prefer streaming fetch (e.g., mysqli_fetch_assoc in a loop)."
# Avoid repeated full-file loads inside loops.
- pattern: "foreach\\s*\\([^)]*\\)\\s*\\{[^}]*file_get_contents\\("
message: "Avoid file_get_contents() inside loops; stream with SplFileObject or read once and reuse."
# Avoid array_merge in tight loops as it copies arrays.
- pattern: "foreach\\s*\\([^)]*\\)\\s*\\{[^}]*=\\s*array_merge\\("
message: "Avoid array_merge() inside loops; append elements directly or preallocate arrays."
# Use caution with range() on large ranges (allocates full array).
- pattern: "\\brange\\s*\\("
message: "range() allocates full arrays; for large ranges consider generators (yield) to avoid high memory."
- type: suggest
message: |
**PHP memory optimisation recommendations:**
- **Stream database results:** Prefer `$stmt->fetch(PDO::FETCH_ASSOC)` in a `while` loop or use generators instead of `fetchAll()`.
- **Use generators (yield):** Iterate large datasets without allocating full arrays.
- **Stream files:** Use `SplFileObject` or chunked reads instead of `file_get_contents()` for large files.
- **Minimise array copying:** Avoid `array_merge()` in loops; push items directly or pre-size with known capacity (e.g., `SplFixedArray`).
- **Free memory explicitly:** `unset($var)` after large data is no longer needed; consider `gc_collect_cycles()` for long-running scripts.
- **Profile memory:** Use `memory_get_usage()` and tools like Xdebug/Blackfire to spot peaks.
- **OPcache:** Ensure OPcache is enabled and sized appropriately in production.
- type: validate
conditions:
# Detect full-file reads that likely could be streamed.
- pattern: "\\bfile\\s*\\("
message: "file() reads entire files into memory; prefer SplFileObject for line-by-line streaming."
metadata:
priority: high
version: 1.0
</rule>
<rule>
name: php_ini_opcache_recommendations
description: Recommend enabling OPcache for lower memory and better performance when editing php.ini
filters:
- type: file_extension
pattern: "\\.ini$"
actions:
- type: suggest
message: |
**OPcache recommendations (php.ini):**
- Set `opcache.enable=1` and `opcache.enable_cli=1` for CLI scripts that process large datasets.
- Size memory pool appropriately, e.g., `opcache.memory_consumption=128` (adjust to your project).
- Consider `opcache.interned_strings_buffer` and `opcache.max_accelerated_files` for larger codebases.
- type: enforce
conditions:
- pattern: "(?mi)^opcache\\.enable\\s*=\\s*0"
message: "Enable OPcache in production (set opcache.enable=1) to reduce memory and CPU overhead."
metadata:
priority: medium
version: 1.0
</rule>
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

