This is a discussion on PHP Threading and global variables within the PHP Language forums, part of the PHP Programming Forums category; Are global variables thread safe? We are seeing competing threads modifying global variables on calls to the same page. We ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Are global variables thread safe? We are seeing competing threads
modifying global variables on calls to the same page. We are running in ISAPI mode. Are globals protected internally inside of the PHP runtime with a semaphore or some other mechanism? |
|
|||
|
"Pat A" <pwalessi1@hotmail.com> wrote in message
news:1107544624.483219.212310@f14g2000cwb.googlegr oups.com... > Are global variables thread safe? We are seeing competing threads > modifying global variables on calls to the same page. We are running in > ISAPI mode. Are globals protected internally inside of the PHP runtime > with a semaphore or some other mechanism? > Yes. They managed, along with all internal data, by TSRM, the PHP thread-safe resource manager. Based on the id of current thread, a block of memory is obtained/allocated by TSRM. The thread data registry itself is protected by a mutex. The behavior you described is rather odd. As far as I know, there is no thread-unsafe version of the PHP engine for Windows. Can you show us some code sample? |
|
|||
|
"Pat A" <pwalessi1@gmail.com> wrote in message news:1108585109.304104.42140@g14g2000cwa.googlegro ups.com... > We're seeing the problem in the free FPDF library. We have a php page > that instantiates the FPDF class multiple times in a loop. The > instances of FPDF seem to be stepping on each other. > Unfortunately, not all PHP extension are threadsafe. You might want to contact the people who wrote FPDF. |
|
|||
|
Chung Leong wrote:
> "Pat A" <pwalessi1@gmail.com> wrote in message > news:1108585109.304104.42140@g14g2000cwa.googlegro ups.com... > >>We're seeing the problem in the free FPDF library. We have a php page >>that instantiates the FPDF class multiple times in a loop. The >>instances of FPDF seem to be stepping on each other. >> > > > Unfortunately, not all PHP extension are threadsafe. You might want to > contact the people who wrote FPDF. > > Don't rely upon PHP being thread safe, the problem doesn't lie neccesarily with PHP, its the libraries PHP employs that may - read are not - thread safe. Assume that any PHP program is running in a thread unsafe environment - better safe than sory <g> |