Zend Thread Safety , how PHP engine works in a threaded env
summary
Zend Thread Safety (ZTS) explains how a PHP build isolates globals so the interpreter can run safely under threads: it uses the tsrm layer to allocate TLS per-thread globals at thread startup (typically backed by pthreads), which adds one-time startup and per-thread allocation cost but avoids locking on every access. Builds are ABI-incompatible so extensions need separate ZTS and non-ZTS binaries; enable it with --enable-maintainer-zts. The userland pthreads extension exists but is experimental and not recommended for production.
AI-written summary · about
chapters (37)
- 0:00Intro
- 0:22Hello everybody
- 1:07TOC Recall on computer parallel programming What are threads ? - Threads VS process
- 2:12Computer architecture
- 3:32Concurrency
- 3:44Parallelism
- 4:16OS Process - The lowest level representation of "a task" - The OS scheduler does the job
- 4:47Processes are heavy
- 5:59Thread infos
- 6:18Threads are light process • Threads have been designed like processes
- 8:49Threads share memory
- 9:26Threads dangers - Threads share the heap and the data segment
- 10:33Threads VS processes
- 11:30PHP Multitasking
- 12:12Multitasking PHP
- 13:50PHP in a threaded env - PHP could leave in a threaded environment
- 16:13Zend Thread Safety - PHP will never itself make use threads
- 17:29ZTS goals ZTS is a way of programming PHP core and extensions, in C
- 17:45ZTS, abstract thread model - Several thread library exists They all got their own behavior/API/ performances
- 19:50TSRM • TSRM stands for Thread Safe Resource Manager
- 20:53Example program
- 22:38TSRM macros Accessing globals while in a thread must be done using TSRM macros
- 23:33Pthread keys
- 24:47Extensions compilation At compilation, each extension declares a pointer to some TLS space
- 26:31TLS storage detail
- 27:39Allocating resources per thread - This is done at every new request
- 28:33Allocating thread resources
- 30:06Extensions thread startup
- 31:07Accessing resources per thread
- 31:57ZTS ? - A nice layer, that eases and abstract all the thread and TLS management
- 33:57When to use ZTS ?
- 35:51Check if ZTS is used
- 37:03ZTS ABI - Obviously, ZTS ABI is not compatible with NTS
- 37:55Using threads in PHP Land
- 41:12Using processes in PHP land
- 42:01ZTS and threads : concluding PHP is thread-safe * Compile with --enable-maintainer-zts - You'll activate Zend Thread Safety
- 43:36Thank you for listening








