r/PHP • • 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.

3 Upvotes

5 comments sorted by

5

u/MateusAzevedo 2d ago

Who is the target, users or developers?

Github link returns 404, by the way.

-1

u/Holden-Carter 2d ago

It's aimed at developers since it involves PHP compatibility checks. As for the 404, that might be due to changes in the repo or permissions. Did you try reaching out on GitHub for updates?

2

u/MateusAzevedo 1d ago

It's aimed at developers

Then why does it need to run on a shared host? Can't Wordpress developers run their projects locally?

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