~/talk

Zend Thread Safety , how PHP engine works in a threaded env

Talkat Dutch PHP Conference 2017 · 2017-06-29..07-01· [php]
slides:none on file

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

  1. 0:00Intro
  2. 0:22Hello everybody
  3. 1:07TOC Recall on computer parallel programming What are threads ? - Threads VS process
  4. 2:12Computer architecture
  5. 3:32Concurrency
  6. 3:44Parallelism
  7. 4:16OS Process - The lowest level representation of "a task" - The OS scheduler does the job
  8. 4:47Processes are heavy
  9. 5:59Thread infos
  10. 6:18Threads are light process • Threads have been designed like processes
  11. 8:49Threads share memory
  12. 9:26Threads dangers - Threads share the heap and the data segment
  13. 10:33Threads VS processes
  14. 11:30PHP Multitasking
  15. 12:12Multitasking PHP
  16. 13:50PHP in a threaded env - PHP could leave in a threaded environment
  17. 16:13Zend Thread Safety - PHP will never itself make use threads
  18. 17:29ZTS goals ZTS is a way of programming PHP core and extensions, in C
  19. 17:45ZTS, abstract thread model - Several thread library exists They all got their own behavior/API/ performances
  20. 19:50TSRM • TSRM stands for Thread Safe Resource Manager
  21. 20:53Example program
  22. 22:38TSRM macros Accessing globals while in a thread must be done using TSRM macros
  23. 23:33Pthread keys
  24. 24:47Extensions compilation At compilation, each extension declares a pointer to some TLS space
  25. 26:31TLS storage detail
  26. 27:39Allocating resources per thread - This is done at every new request
  27. 28:33Allocating thread resources
  28. 30:06Extensions thread startup
  29. 31:07Accessing resources per thread
  30. 31:57ZTS ? - A nice layer, that eases and abstract all the thread and TLS management
  31. 33:57When to use ZTS ?
  32. 35:51Check if ZTS is used
  33. 37:03ZTS ABI - Obviously, ZTS ABI is not compatible with NTS
  34. 37:55Using threads in PHP Land
  35. 41:12Using processes in PHP land
  36. 42:01ZTS and threads : concluding PHP is thread-safe * Compile with --enable-maintainer-zts - You'll activate Zend Thread Safety
  37. 43:36Thank you for listening
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.