Slide 1

Slide 1 text

Benjamin Eberlei Winning @ PHP in Production 2025 High-Performance, -Availability Benjamin Eberlei

Slide 2

Slide 2 text

Why care? Isn’t PHP getting faster every version?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Benchmarks show no gain during 8.x series

Slide 5

Slide 5 text

Benchmarks show no gain during 8.x series

Slide 6

Slide 6 text

Lets start with php.ini settings

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Lets start with php.ini settings

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

More php.ini settings ● display_errors=off ● log_errors=on ● error_log=/var/log/php/php_error.log ● Looking for max time exceeded, max memory limit reached errors

Slide 13

Slide 13 text

Canonical Application Log Lines ● https:/ /stripe.com/blog/canonical-log-l ines ● key=value pairs in a text log ● “Nginx/Apache log for Application”

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

PHP-FPM ● Prefer pool “static” ● Calculate max_children based on available memory ● https:/ /tideways.com/tools/fpm-configu ration-calculator

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

CPU, I/O or Memory bound? ● Watch Scheduler Statistics ● https:/ /docs.kernel.org/scheduler/sche d-stats.html ● If difference is 0 after request, no scheduling took place.

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

● fpm_get_status() ● pm.status_path=/fpm-status

Slide 20

Slide 20 text

Multiple PHP-FPM Pools

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Opcache Three critical settings to adjust:

Slide 24

Slide 24 text

Opcache Monitoring ● opcache_get_status

Slide 25

Slide 25 text

Opcache Preloading ● opcache.preload ● Moves autoloading and include time “off-request”

Slide 26

Slide 26 text

JIT 🤷

Slide 27

Slide 27 text

Sessions ● Default Filesystem handler does not scale beyond one application server ● Be aware of Session locking

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Sessions ● Default Filesystem handler does not scale beyond one application server ● Locking of sessions

Slide 31

Slide 31 text

Composer Optimize Autoload

Slide 32

Slide 32 text

File Storage ● Avoid Network File System (NFS) for the whole application ● only to share assets/files if you must

Slide 33

Slide 33 text

Timeouts Reduce the connect timeouts of everything, defaults break your neck ● default_socket_timeout ✅ ● Redis default 5 seconds ● cURL indefinitely waiting ○ A

Slide 34

Slide 34 text

Health Checks https:/ /github.com/spatie/laravel-health https:/ /github.com/laminas/laminas-diag nostics Are services + processes up?

Slide 35

Slide 35 text

Background Jobs ● Use Symfony Messenger ● Supervisord ● Canonical log lines (again!) ● Health Checks & Restart automatically

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

High Availability PHP ● Load Balancing in front of app servers ● Web servers only run php-fpm ● Independent worker and cron servers ● Databases and caches have their servers ● each system redundant or clustered if you want to avoid single point of failure

Slide 38

Slide 38 text

InnoDB Buffer Pool Size is often too small

Slide 39

Slide 39 text

THANKS E-Mail: [email protected] YouTube: https:/ /youtube.com/@TidewaysPHP Mastodon: https:/ /phpc.social/@beberlei