跳到正文
DEV Community· Stratos·· 2 小時前AI 評分43

PHP 8.6 與 PHP 8.5 在 Apple Silicon 上的基準測試:原生 FPM Unix Socket 與 Docker Desktop VirtioFS

Benchmarking PHP 8.6 vs 8.5 on Apple Silicon: Native FPM Unix Sockets vs Docker Desktop VirtioFS

AI 導讀

文章比較 Apple Silicon 上原生 PHP-FPM Unix Socket 與 Docker Desktop VirtioFS 執行 PHP 的差異,並提供唯讀 MIT Bash 腳本,讓用戶在自己的 Mac 上量度效能。

正文

Stratos

Every time a developer complains that Laravel or WordPress feels sluggish on an M3 or M4 MacBook, someone replies "Just use Docker!" — and someone else replies "Just go native!"

Instead of arguing in the abstract, let's look at why file-heavy PHP frameworks behave differently on macOS vs Linux, and share a read-only MIT bash script you can run on your own Mac in 15 seconds to measure the real difference.


1. The macOS VirtioFS Tax on PHP Autoloaders

A single uncached Laravel or WordPress request touches hundreds to thousands of PHP files across vendor/, compiled Blade views, and config caches.

  • On Linux, Docker bind mounts hit the host kernel VFS directly with negligible overhead.
  • On macOS, Docker Desktop must boot a Linux VM (Apple Virtualization Framework + VirtioFS) and marshal every stat(), open(), and realpath() call across the VM boundary — while keeping gigabytes of unified RAM allocated even when your editor is closed.

When you instead run native macOS Darwin binaries — Nginx talking to per-version PHP-FPM Unix domain sockets (php83-fpm.sock, php84-fpm.sock, php85-fpm.sock, php86-fpm.sock) directly over APFS — the VM boundary disappears completely.


2. Benchmark Your Own Mac (Read-Only, Zero Changes)

You can run our open-source diagnostic script directly inside any local Laravel project:

curl -fsSL https://stratosapp.dev/tools/macos-laravel-stack-benchmark.sh | bash -s -- .

(Inspect the full source first at khorshedobs/macos-php-laravel-toolkit — 100% read-only MIT bash!)

It prints three concrete metrics for your machine:

  1. Live Process Memory (RSS MB): Sums nginx, dnsmasq, and php-fpm vs active Docker Desktop / virtualization VM processes.
  2. 20-Iteration PHP CLI Cold Startup (php -r "echo 1;"): Average, min, and max milliseconds per spawn.
  3. 10-Iteration Laravel php artisan --version Boot Latency: Measures real Composer autoloader + framework container bootstrap time.

3. Running PHP 8.4, 8.5, and 8.6 Side-by-Side Without Container Rebuilds

One reason developers reached for Docker in the past was testing a new PHP release (like PHP 8.6 this week!) without breaking older client sites.

With isolated Unix sockets, you get the exact same isolation natively:

  • Client App A stays pinned to unix:/.../php83-fpm.sock
  • Client App B stays pinned to unix:/.../php84-fpm.sock
  • Your PHP 8.6 upgrade branch runs in a git worktree on unix:/.../php86-fpm.sock

Zero brew unlink, zero port 9000 collisions, and zero VM rebuilds.


4. Tools & References

Drop your own macos-laravel-stack-benchmark.sh numbers (M1/M2/M3/M4 + Docker vs Native) in the comments — would love to compare across different MacBooks!

來源:DEV Community · dev.to