Search code examples
phpiis-7.5windows-server-2008-r2

Does non thread safe in PHP have implications on database CRUD?


I have read several articles and answers on SO. When it comes to database insert, delete, etc., does thread safety matter? Can something be inserted in the wrong record, for example? What exactly is going to get hosed up if I abandon "safety"?

I am using Windows 2008 R2, IIS 7.5.


Solution

  • Dagon is correct - thread safety is critical for any operation.

    Can something be inserted in the wrong record, for example?

    There's two questions here:

    1) is PHP thread safe?

    2) what happens if it's not thread safe?

    In regard to the first question, the PHP core engine is thread safe and has been for a number of years. However a working PHP installation incorporates multiple extensions from various sources - and the guys who write PHP are not in a position to guarantee that someone else's code behaves as expected.

    In regard to the second question, yes if the code is running as lightweight processes and is not thread safe, then your data could get messed up - more likely it will just crash: and since (AFAIK) the threaded PHP only works with the IIS ISAPI module (leaving aside the threads PECL) that means it'll probably take out the whole IIS instance.

    But the question you need to answer BEFORE you consider any of these is whether there is any benefit to using ISAPI threads rather than fastCGI and PHP. Personally, I would avoid a Micorosft platform for reasons of performance, reliability, not to mention my own sanity - but I do sometimes get involved in fixing other peoples problems. However I've not seen any benchmarks showing that ISAPI has any performance advantage, which might explain why it's dropped as of version 5.3.0 (on Linux there is no performance benefit but a very small capacity improvement of around 5%).