2

I develop actually an PHP extension (PHP 5.6) (this extension will be only used on Linux server), in this extension I would like to use C pthread.

Is it possible to make an PHP extension which uses pthread, without having to compile PHP with the ZTS option ?

Because there is an extension to be able to use pthread with php but this extension requires the compilation of php with the zts option. pthreads requires

simon
  • 1,180
  • 3
  • 12
  • 33

1 Answers1

0

It is possible to use threading in a PHP extension without ZTS mode enabled, but the threads must not interact with any of the internal functions (including PHP code itself). This is because without ZTS mode enabled, nothing is thread-safe (obviously), and there's quite a lot of global state in the Zend Engine (ZE). So you're quite limited as to what you can do with threads in this case.

If you do enable ZTS mode, then threads may interact with any internal functions and PHP code, but a shared-nothing architecture must be employed. This is because there are some parts of ZE that are still not thread-safe - most notably, the Zend Memory Manager (ZMM). This means that for each thread, a separate copy of PHP's interpreter must be made (which packs with it its own ZMM), where all functions, classes, interfaces, traits, etc, are copied over to this new interpreter instance to execute things in an entirely separate context.

tpunt
  • 2,552
  • 1
  • 12
  • 18