r/PHP • • 16h ago

Creating a roaring bitmap extension

Thumbnail github.com
5 Upvotes

r/PHP • • 20h ago

Discussion Running PHPCompatibility inside WordPress without exec(): what I learned

2 Upvotes

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.


r/PHP • • 4h ago

Intelephense vs. Intellisense

Thumbnail intelephense.com
0 Upvotes

I've just found out Intellisense is an implementation of the code completion from Microsoft, NOT the general term - and I was using that way 🤦‍♂️

PHP has Intelephense. Am I getting it right?


r/PHP • • 8h ago

Article What PHP’s session vulnerability teaches us about atomicity

0 Upvotes

PHP’s recent session-file vulnerability, CVE-2026-126714, highlights an easy-to-miss distinction: file locking prevents competing writers, but it doesn’t make a write atomic.

If a session write is interrupted, the file can end up containing a prefix of the new serialized session followed by leftover bytes from the old one. Under the right conditions, that can turn corrupted session data into remote code execution.

I wrote about what happened, how PHP fixed it by truncating the file before every write, and why a lock isn’t the same thing as a transaction.

Read the article: https://amitmerchant.com/what-phps-session-handler-teaches-us-about-atomicity/


r/PHP • • 55m ago

Discussion Googlebot caused 485k disk writes in one hour on my PHP site. Sessions and counters were the part I could cut

0 Upvotes

I'm building Rezervomat, an online booking system for small businesses, on top of the Osclass PHP core. On 24 November the hosting IO chart for the production site showed a peak of about 485k write operations in one hour. The access log had Googlebot crawling our documentation in 7 languages at roughly 1,500 requests an hour.

3 things were writing on every anonymous request. The core started a PHP session and stored a session file even for a cookie-less crawler request. Our own per-visit counters (page cache stats, rate limits, a crawler hit table) wrote to files or the database on every page view. And blog views were counted for bots too.

What I've changed: a cookie-less GET from a crawler user agent no longer gets a stored session. I added increment() to the object cache backends in the core, so counters live in APCu or memcache instead of files and the database, and page cache stats are appended in 5-minute slots instead of per request. The crawler hit table is gone completely.

I haven't confirmed how much of the remaining IO is MySQL temp tables on disk, and I only tested the increment path on APCu, not memcache. If the spikes come back I'll run the query log for one crawl hour.

For those of you who run PHP sites with a lot of bot traffic: do you skip sessions and counters for known crawlers by user agent, or let them through and filter later? I don't fully trust the user agent, so for the bots that matter I also check reverse DNS.


r/PHP • • 18h ago

Laravel Safe Migrations v1.1: catch dangerous migrations before they hit production (updated with your feedback)

0 Upvotes

Hi everyone,

A while ago I shared Laravel Safe Migrations, a package that checks your pending migrations for things that can break production before you run migrate. Thanks for all the feedback last time. Several suggestions from that thread are now in the package.

How it works

It dry-runs your pending migrations in Laravel's pretend mode, collects the SQL they would execute, and checks it against a set of rules. Because it reads the SQL and not your PHP code, it also catches DB::statement(), DB::unprepared() and query builder calls.

php artisan safe-migrations:check ERROR [drop-column] Dropping column [users.legacy] destroys its data, and app servers still running the old code will fail on queries that use it. → Remove every use of the column from the code and deploy that first, then drop the column in a follow-up migration. What it catches

Dropping or renaming tables and columns that the old code still uses during the deploy NOT NULL columns without a default on tables that already have rows Column type changes that rewrite the whole table PostgreSQL: blocking CREATE INDEX, foreign keys without NOT VALID, and SET NOT NULL UPDATE / DELETE without WHERE, and TRUNCATE Tables created earlier in the same batch are ignored, since they have no data yet New since last time

concurrent-in-transaction rule: flags CREATE INDEX CONCURRENTLY in a migration that Laravel wraps in a transaction, which PostgreSQL rejects. The fix is public $withinTransaction = false;. (Suggested in the last thread, thanks!) Side effects are faked during the check: HTTP calls, mail, notifications, queued jobs and dispatch() inside up() no longer actually happen while the migration is analysed. Migrations with their own $connection are now checked against the right database. SQL comments can't hide a statement from the check anymore. Three ways to use it

In CI: safe-migrations:check fails the pull request if a migration is unsafe. In deploys: php artisan migrate:safe --force checks first, then migrates. As a guard: set SAFE_MIGRATIONS_GUARD=true and plain migrate refuses unsafe migrations in production. When a risky change is intentional, mark the migration so the reason stays in code review:

return new #[AllowUnsafe('drop-column', reason: 'unused since v2.3')] class extends Migration { ... }; Honest limitations

Pretend mode returns no data, so a migration that branches on Schema::hasColumn() is checked along the "empty" path. It can't know your table sizes. A warning on a 200-row table may not matter. File and cache writes inside up() still run during the check. Supports Laravel 12/13 on MySQL/MariaDB, PostgreSQL and SQLite. SQL Server isn't supported. Install

composer require hamza-wakrim/laravel-safe-migrations GitHub: https://github.com/Hamza-Wakrim/laravel-safe-migrations

I'd love feedback, especially false positives or problems it missed on your real migrations, and rule ideas from your zero-downtime deploys. MySQL lock detection (instant vs. table-copy changes) is next on my list.


r/PHP • • 21h ago

News Update: MicroUnit got featured on Laravel News and phpnews.net

0 Upvotes

A couple of days ago I posted about MicroUnit, a dependency-free PHP testing framework.

And today was a big day for it.

First it got featured on Laravel-News, which was already a nice milestone.

But then: I sent a tip to Eric Barnes, the founder and editor of Laravel News and phpnews.net, about the 1.0 release, and he wrote an article about MicroUnit himself.

It's already live: https://phpnews.net/microunit

I just wanted to say thanks to everyone who gave me feedback for MicroUnit and helped me make the framework better over the last few days.

If you wanna try out MicroUnit: