0

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?

Henry
  • 1,395
  • 1
  • 12
  • 31
  • 1
    avoiding your main question, and assuming that you have read https://stackoverflow.com/questions/1623914/what-is-thread-safe-or-non-thread-safe-in-php?rq=1 I would upgrade to 8.2. it is a minor upgrade. I would only worry about thread safety if you are running concurrent applications – JoSSte Dec 27 '22 at 20:20
  • I believe, but can’t say for certain, that non-thread safe is mostly recommended unless you plan to run PHP in a certain fashion which, if memory serves me correctly, isn’t the default for most installs and thus not common. This choice will have zero effect on coding and thus zero effect on production hosting, unless you are responsible for infrastructure. Laravel Sail might be something you want to look into, too. – Chris Haas Dec 27 '22 at 20:46
  • Thank you JoSSte and Chris! – Henry Dec 28 '22 at 17:37

1 Answers1

2

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.

Frederickcjo
  • 323
  • 1
  • 9
  • Thank you, Frederickcjo! I discovered that I am running a thread-safe version of PHP even though I didn't specifically chose that. Your answer makes it clear that I don't need to upgrade my PHP to 8.2.0 but I think I will anyway just for the practice in the correct technique. Then I will install XDebug for 8.2.0 thread-safe so that everything is compatible and up-to-date, at least for a little while. Thank you for all your valuable guidance!! – Henry Dec 28 '22 at 17:41