Why PHP has separate version of ts(thread safe)/nts(non thread safe) while it doesn't support multi-threading?

后端 未结 1 1817
悲&欢浪女
悲&欢浪女 2021-02-04 08:23

I think the title is clear.

1条回答
  •  旧时难觅i
    2021-02-04 09:10

    While you can't spawn threads from PHP code you can use PHP with a multi-threaded web server that handles concurrent requests on different threads. In this case the TS (thread-safe) version of PHP should be used.

    The TS version of PHP keeps the state of each request in its own memory location. This is necessary because all requests in a multi-threaded server share the same address space.

    The alternative is to use a multi-process (usually prefork) server. With such a server some state can be kept in global variables without affecting concurrent requests. That's how the NTS (non thread-safe) version of PHP is implemented.

    0 讨论(0)
提交回复
热议问题