PHP Threading and global variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pat A

    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?

  • Pat A

    #2
    Re: PHP Threading and global variables


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

    Comment

    • Chung Leong

      #3
      Re: PHP Threading and global variables

      "Pat A" <pwalessi1@hotm ail.com> wrote in message
      news:1107544624 .483219.212310@ f14g2000cwb.goo glegroups.com.. .[color=blue]
      > 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?
      >[/color]

      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?


      Comment

      • Pat A

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

        Comment

        • Chung Leong

          #5
          Re: PHP Threading and global variables


          "Pat A" <pwalessi1@gmai l.com> wrote in message
          news:1108585109 .304104.42140@g 14g2000cwa.goog legroups.com...[color=blue]
          > 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.
          >[/color]

          Unfortunately, not all PHP extension are threadsafe. You might want to
          contact the people who wrote FPDF.


          Comment

          • noSpam

            #6
            Re: PHP Threading and global variables

            Chung Leong wrote:[color=blue]
            > "Pat A" <pwalessi1@gmai l.com> wrote in message
            > news:1108585109 .304104.42140@g 14g2000cwa.goog legroups.com...
            >[color=green]
            >>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.
            >>[/color]
            >
            >
            > Unfortunately, not all PHP extension are threadsafe. You might want to
            > contact the people who wrote FPDF.
            >
            >[/color]
            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>

            Comment

            Working...