PHP Threading and global variables

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-04-2005
Pat A
 
Posts: n/a
Default PHP Threading and global variables

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?

Reply With Quote
  #2 (permalink)  
Old 02-04-2005
Pat A
 
Posts: n/a
Default Re: PHP Threading and global variables


By the way, we are only seeing this on a multi-processor machine.

Reply With Quote
  #3 (permalink)  
Old 02-05-2005
Chung Leong
 
Posts: n/a
Default Re: PHP Threading and global variables

"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?


Reply With Quote
  #4 (permalink)  
Old 02-16-2005
Pat A
 
Posts: n/a
Default Re: PHP Threading and global variables

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.

Reply With Quote
  #5 (permalink)  
Old 02-17-2005
Chung Leong
 
Posts: n/a
Default Re: PHP Threading and global variables


"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.


Reply With Quote
  #6 (permalink)  
Old 02-17-2005
noSpam
 
Posts: n/a
Default Re: PHP Threading and global variables

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>
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0