r/PHP • u/13heyitsme • 2d ago
Discussion Running PHPCompatibility inside WordPress without exec(): what I learned
I wanted a PHP 8.x compatibility check that works on shared WordPress hosting, where you can't run phpcs from the command line and requests time out after 30 seconds. So I ended up running PHP_CodeSniffer and PHPCompatibility inside a plugin. A few things I had to solve:
- Scoping the bundled PHPCS with PHP-Scoper so it doesn't clash with other plugins, and fixing the cases where Scoper prefixes strings it shouldn't (class names that are data, like Random\Randomizer).
- A Config subclass that never reads argv or STDIN, since there is no CLI.
- Splitting the scan into chunks of a few seconds, saved in the database, so it can stop and resume.
- Telling real problems apart from code that is already wrapped in a PHP version check.
Happy to go into detail on any of these.
5
u/MateusAzevedo 2d ago
Who is the target, users or developers?
Github link returns 404, by the way.
2
u/Gabisimeli-Falase 2d ago
how did you handle the memory ceiling on shared hosts alongside the timeout? Tokenizing large files in memory usually hits the RAM limit way before the 30 second execution timer runs out