Title: eval-file silently does nothing on large files (PCRE JIT stack limit swallowed) · Issue #97 · wp-cli/eval-command · GitHub
Open Graph Title: eval-file silently does nothing on large files (PCRE JIT stack limit swallowed) · Issue #97 · wp-cli/eval-command
X Title: eval-file silently does nothing on large files (PCRE JIT stack limit swallowed) · Issue #97 · wp-cli/eval-command
Description: Executes arbitrary PHP code or files. Contribute to wp-cli/eval-command development by creating an account on GitHub.
Open Graph Description: Executes arbitrary PHP code or files. Contribute to wp-cli/eval-command development by creating an account on GitHub.
X Description: Executes arbitrary PHP code or files. Contribute to wp-cli/eval-command development by creating an account on GitHub.
Opengraph URL: https://github.com/wp-cli/eval-command
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"eval-file silently does nothing on large files (PCRE JIT stack limit swallowed)","articleBody":"BODY:\nI ran into a case where `wp eval-file some-script.php --url=...` would exit 0 with zero output and make none of the changes the script was supposed to make — no error, no warning, nothing in any log. It took a lot of digging to figure out why.\n\nThe script in question was about 26KB, mostly a bunch of heredoc-wrapped HTML content with lots of quoted strings and `https://` URLs. Small test scripts (guard checks, a single function call, etc.) ran fine every time. It was specifically the full, large file that failed, and it failed 100% reproducibly, both through a normal terminal invocation and independently.\n\nDigging into `EvalFile_Command::execute_eval()`, without `--use-include` it does:\n\n```php\n$file_contents = file_get_contents( $file );\n$file_contents = Utils\\replace_path_consts( $file_contents, $file );\neval( '?>' . $file_contents );\n```\n\n`replace_path_consts()` runs a `preg_replace_callback()` over the whole file (to rewrite `__FILE__`/`__DIR__` tokens) using a fairly heavy atomic-group regex that skips comments and quoted strings. On my file, that call was returning `null` — `preg_last_error()` came back `6` (`PREG_JIT_STACKLIMIT_ERROR`). Since the code doesn't check for that, `$file_contents` becomes `null`, and `eval('?>' . null)` just... does nothing. No exception, no warning, exit code 0.\n\nThe part that made this so hard to track down: it only happens once WordPress and all its plugins are already loaded (this site has ~30 active plugins). A bare `php -r` test of the exact same regex against the exact same file content, outside of that deep call stack, never reproduced it — presumably because there's less PCRE JIT stack headroom left once WP-CLI's own call stack is already several layers deep. So the obvious way to debug it (extract the regex, test it standalone) makes the bug disappear.\n\n`--use-include` sidesteps all of this (plain `include()`, no eval, no regex pass) and worked immediately.\n\nTwo things that'd have saved me a lot of time:\n- Checking `preg_last_error()` after the `preg_replace_callback()` call and raising a proper `WP_CLI::error()` if it fails, instead of silently eval-ing `null`.\n- Maybe a note in the `eval-file` docs that `--use-include` is the safer choice for anything beyond a small script, given eval() plus a regex rewrite pass is inherently more fragile than a plain include.\n\nI'm able to share the script file if it'd help, though it's mostly just a lot of HTML.\n\nEnvironment: PHP 8.4, WP-CLI 2.12.0, pcre.jit=On, pcre.backtrack_limit/recursion_limit at PHP defaults (1000000/100000).\n","author":{"url":"https://github.com/jamespostsil","@type":"Person","name":"jamespostsil"},"datePublished":"2026-09-14T22:35:42Z","url":"https://github.com/wp-cli/eval-command/issues/97"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:7ebc1480-2e5f-344e-c54c-3d3b51b82d55 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E120:3C4F8E:1686830:1F4066E:6AFA6930 |
| html-safe-nonce | dc9d21e828a6883ef6ee68bacb9d1595e077d7988e0b926f920536783509a4bf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTIwOjNDNEY4RToxNjg2ODMwOjFGNDA2NkU6NkFGQTY5MzAiLCJ2aXNpdG9yX2lkIjoiNzk2MzgwNjE4Njg0NTM5OTM0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3e40b76bd67c72c96610af4d2d58100e6d1697e6bdae6b58e35ae43071517de9 |
| hovercard-subject-tag | repository:85580543 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/wp-cli/eval-command/issues/97 |
| twitter:image | https://opengraph.githubassets.com/d0d2d5e4ecd39acc432fc8be630d910b0247b023d4f4c4156934ceeb341d2bcc/wp-cli/eval-command |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d0d2d5e4ecd39acc432fc8be630d910b0247b023d4f4c4156934ceeb341d2bcc/wp-cli/eval-command |
| og:image:alt | Executes arbitrary PHP code or files. Contribute to wp-cli/eval-command development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| turbo-cache-control | no-cache |
| go-import | github.com/wp-cli/eval-command git https://github.com/wp-cli/eval-command.git |
| octolytics-dimension-user_id | 1570774 |
| octolytics-dimension-user_login | wp-cli |
| octolytics-dimension-repository_id | 85580543 |
| octolytics-dimension-repository_nwo | wp-cli/eval-command |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 85580543 |
| octolytics-dimension-repository_network_root_nwo | wp-cli/eval-command |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 072e34035c13c31543fba9f025cbbbda4210dae4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width