Home > OS >  How do I choose between thread-safe and not thread-safe PHP?
How do I choose between thread-safe and not thread-safe PHP?

Time:12-29

I am developing a Laravel 9.x app in Windows 10. My current version of PHP is PHP 8.1.5 (cli) (built: Apr 12 2022 17:38:57) (ZTS Visual C 2019 x64). Is this a thread-safe or not-thread-safe version? How can I tell? When should I prefer a thread-safe over a not-thread-safe version?

I've tried researching this issue here on StackOverflow but the questions/answers I see all seem to be a decade or more old - like this - and I strongly suspect that I might get a different answer if I asked the question today simply because the technology has changed in the intervening years. Is that a reasonable assumption? (At the very least, my current version of PHP evidently uses a newer compiler, VC 2019, rather than VC6 or VC9.)

I have no idea yet what my production environment is going to be or even IF the app I'm developing will ever go to a production environment since it's just an app I'm writing to (re-)learn Laravel. I may put it in production as a demonstration of a working Laravel app when the time comes but whether it will be on a hosting service or Netlify or something else, I just don't know at this point.

Just to give you some context, this issue only came up because I am trying to learn how to step through my Laravel source code to debug problems and this apparently requires me to add XDebug to XAMPP. The instructions I found for installing XDebug point me to here and recommend that I download the Windows binaries for my version of PHP. There are no binaries of 8.1.5 so I don't know if one of the binaries for 8.1 would work or if I'd be better to use 8.1 thread-safe or 8.1 not-thread-safe. If it would be better to upgrade my PHP first to 8.2, I still don't know if thread-safe or not-thread-safe is a better choice.

Can someone enlighten me on these matters?

CodePudding user response:

Is this a thread-safe or not-thread-safe version? How can I tell?

You can use the good old phpinfo() function and lookup for the Thread Safety column.

If you have your PHP setup in PATH environment, you can even get it via CLI using a quick command php -i | grep Thread

When should I prefer a thread-safe over a not-thread-safe version?

As per PHP official documentation

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.

I have no idea yet what my production environment is going to be ...

Generally, there is no difference on TS or NTS code execution. It's more towards the webserver.

If I am not mistaken, by default, XAMPP uses Apache Handler, so it will likely be a thread safe build. And yes, the Xdebug binary for PHP8.1 will just work fine.

Technically, NTS should be slightly faster because it doesn't need to cater for thread safety.

Personally, I think it doesn't matter, unless you want to spend slightly more time to tinker around the webserver switching to FastCGI or PHP-FPM, since you are still in development phase, I think stick to the default setup and focusing on getting it up is more efficient.

  • Related