php multithreading thread-safety packages thread context
Thread Safety:
Thread Safety means that binary can work in a multithreaded webserver context, such as Apache 2 on Windows. …
For multithreaded webservers, such as IIS5 and IIS6, you should use the threaded version of PHP.
Non-Thread Safe:
If you choose to run PHP as a CGI binary, then you won’t need thread safety, because the binary is invoked at each request.
For multithreaded webservers, such as IIS5 and IIS6, you should use the threaded version of PHP. … Apache + FastCGI: Non-Thread Safe. IIS: Thread Safe
Uses of thread safe and non-thread safe:
A thread-safe version should be used if you install PHP as an Apache module, as a worker MPM (multi-processing model).
The non-thread safe version should be used if you install PHP as a CGI binary.
FastCGI
FastCGI is a binary protocol for interfacing interactive programs with a web server.
FastCGI is a variation on the earlier Common Gateway Interface (CGI).
FastCGI’s main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page requests at once.
[ad type=”banner”]What does thread safety mean when downloading PHP
Thread Safety means that binary can work in a multithreaded webserver context, such as Apache 2 on Windows.
Thread Safety works by creating a local storage copy in each thread, so that the data won’t collide with another thread.
So what do we choose? If you choose to run PHP as a CGI binary, then you won’t need thread safety, because the binary is invoked at each request.
For multithreaded webservers, such as IIS5 and IIS6, you should use the threaded version of PHP.
Following Libraries are not thread safe. They are not recommended for use in a multi-threaded environment.
SNMP (Unix)
mSQL (Unix)
IMAP (Win/Unix)
Sybase-CT (Linux, libc5)
Difference between PHP thread safe and non thread safe binaries
There have been a few options available for a while to get PHP performing well on IIS.
Firstly is the use of an opcode cache such as eAccelerator which stores PHP scripts in a partically precompiled state on disk and/or memory which drastically decreases script execution time.
Another option is to configure IIS to use PHP in FastCGI mode which allows PHP processes to be recycled rather than killed off after each PHP request and also allows you to run several PHP processes at once, making PHP much much faster with the added bonus that as it is using the CGI interface there is little or no incompatibility issues with PHP extensions.
This is still the fastest way to serve PHP, and is the way the IIS Aid PHP Installer is configured to install PHP on your IIS Environment.
What the non thread safe binaries allow you to do is to configure IIS (and other Windows based webservers) to use PHP as a standard CGI interface with massively increased performance as the PHP process is not required to wait for thread syncronisation.
The performance increase is not to be sneezed at either as seen figures of upto 40% mentioned (though I’m yet to confirm myself), but it is still not as fast as the opcode/FastCGI method mentioned above.
One of the biggest catches we seen people getting themselves hooked on is that non thread safe binaries cannot be reliably used with the thread safe ones, and vise versa.
This means that (for the moment at least) you cannot use opcode cache systems such as eAccelerator to give your non thread safe PHP environment a boost in the arm as they are all currently compiled as thread safe.
If the non thread safe binaries are not as fast as what you can configure the thread safe binaries to be then what is the point you ask? Here we come back to FastCGI, and in particular the efforts Microsoft have been making over the last year or so with the development of their own FastCGI handler.
This new FastCGI handler from Microsoft enables you to configure the non thread safe PHP binaries in FastCGI mode, which is one massive shot in the arm for performance.
Easiest way to put it is using the non thread safe PHP binaries with Microsoft’s new FastCGI handler is like putting twin turbos on your car (without the inherent risk of blowing up your engine), and there is little doubt in my mind that this will be the future of PHP on IIS.
PHP Thread Safe and Non-Thread Safe for Windows:
Thread Safety means that binary can work in a multithreaded webserver context, such as Apache 2 on Windows.
Thread Safety works by creating a local storage copy in each thread, so that the data won’t collide with another thread.
So what do I choose? If you choose to run PHP as a CGI binary, then you won’t need thread safety, because the binary is invoked at each request. For multithreaded webservers, such as IIS5 and IIS6, you should use the threaded version of PHP.
So for example, if you use FastCGI with Apache, go for the non-thread safe, and if you use LoadModule, go for the thread-safe version.
So it really depends on the way that you want to use PHP:
Apache + LoadModule: Thread Safe
Apache + FastCGI: Non-Thread Safe
IIS: Thread Safe
IIS + FastCGI: Non-Thread Safe
AFAIR running PHP with FastCGI is the preferable way.
It performs faster and allows for more fine-grained security configuration.
[ad type=”banner”]