Which php thread safe




















Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end. Does ES6 make JavaScript frameworks obsolete? Featured on Meta. Now live: A fully responsive profile. Linked 0. Related 2. Hot Network Questions. How can this be non-atomic? But note that lack-of-tearing is not the only thing that std::atomic gives you. I'm a little bit surprised about the evolving discussion concerning the potential relation of volatile to this issue.

Thus, I'd like to spent my two cents:. Lots of ways to deal with this. A simple way is to just not make the timer periodic, make it a one shot by only setting the dueTime argument. Then re-enable the timer in the callback in a finally block. That guarantees that the callback cannot run concurrently. This is of course makes the interval variable by the execution time of the callback. If that's not desirable and the callback only occasionally takes longer than the timer period then a simple lock will get the job done.

Yet another strategy is Monitor. TryEnter and just give up on the callback if it returns false. None of these are particularly superior, pick what you like best. The problem lies in the transactions that are used in test cases when transactional fixtures are on - changes to data are not visible to other connections as long as the transaction is not committed.

As a consequence changes to the database are not seen outside your connection until the operation is complete. And this would be correct thinking. However, as it happens, PHP's thread-safety is highly disputed.

It's a use-if-you-really-really-know-what-you-are-doing ground. In case you are wondering, my personal advice would be to not use PHP in a multi-threaded environment if you have the choice! If you are going to use other webservers such as nginx or lighttpd , you won't have the option to embed PHP into them anyway.

You will be looking at using FastCGI or something equal which works in a different model where PHP is totally outside of the web server with multiple PHP processes used for answering requests through e. For such cases, thread-safety also doesn't matter. Finally, if thread-safety doesn't matter so which version should you use -- the thread-safe or the non-thread-safe?

Frankly, I don't have a scientific answer! For me, I always choose non-thread safe version because I always use nginx, or run PHP from the command line. The non-thread safe version should be used if you install PHP as a CGI binary, command line interface or other environment where only a single thread is used.

Performance-wise it is fairly inefficient. That way you can use the much faster MPM Worker. The whole PHP remains non-threaded, but Apache serves threaded like it should. It only supports non-process managed FastCGI scripts. As per PHP Documentation ,. 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. Following Libraries are not thread safe. They are not recommended for use in a multi-threaded environment.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. What is thread safe or non-thread safe in PHP?



0コメント

  • 1000 / 1000