PHP and Multi-thread

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

    PHP and Multi-thread

    Hi All,

    I can not find any information if PHP support multi-thread (Posix
    thread) or not at all, can someone give out some information? Is it
    supported? If yes, where's the info? If no, is it possible to make
    doing multi-thread stuff?

    Thanks.

    YF
  • Chris Hope

    #2
    Re: PHP and Multi-thread

    OutsiderJustice wrote:
    [color=blue]
    > I can not find any information if PHP support multi-thread (Posix
    > thread) or not at all, can someone give out some information? Is it
    > supported? If yes, where's the info? If no, is it possible to make
    > doing multi-thread stuff?[/color]

    You can do it, but don't try doing it when it's a script on a webserver.
    Check out the following links (the 1st one is the PHP manual; the 2nd one
    is a link on my website about how to do just this):

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.



    Chris

    --
    Chris Hope
    The Electric Toolbox Ltd

    Comment

    • OutsiderJustice

      #3
      Re: PHP and Multi-thread

      Chris Hope <blackhole@elec trictoolbox.com > wrote in message news:<7xObc.480 6$d%6.87672@new s.xtra.co.nz>.. .[color=blue]
      > OutsiderJustice wrote:
      >[color=green]
      > > I can not find any information if PHP support multi-thread (Posix
      > > thread) or not at all, can someone give out some information? Is it
      > > supported? If yes, where's the info? If no, is it possible to make
      > > doing multi-thread stuff?[/color]
      >
      > You can do it, but don't try doing it when it's a script on a webserver.
      > Check out the following links (the 1st one is the PHP manual; the 2nd one
      > is a link on my website about how to do just this):
      >
      > http://www.php.net/pcntl
      > http://www.electrictoolbox.com/artic...ocess-forking/
      >
      > Chris[/color]

      Unfortunately there are so many problems with it:

      - it is not really multi-thread, it's multi-process, it's expensive to
      duplicate all resources in the child process
      - it is only available on UNIX system; even so, if one forgot to do
      '--enable-pcntl' when compiling PHP, one has to compile it again,
      which can be a hassle.

      I'm not a Windows guy, but I believe Windows also has it's own process
      control APIs, so I'm kind of wondering why this is not implemented on
      Windows version.

      Is there anything may be useful to achieve multi-thread performance on
      Windows system?

      Yufeng

      Comment

      • Chris Hope

        #4
        Re: PHP and Multi-thread

        OutsiderJustice wrote:
        [color=blue]
        > Unfortunately there are so many problems with it:
        >
        > - it is not really multi-thread, it's multi-process, it's expensive to
        > duplicate all resources in the child process
        > - it is only available on UNIX system; even so, if one forgot to do
        > '--enable-pcntl' when compiling PHP, one has to compile it again,
        > which can be a hassle.
        >
        > I'm not a Windows guy, but I believe Windows also has it's own process
        > control APIs, so I'm kind of wondering why this is not implemented on
        > Windows version.
        >
        > Is there anything may be useful to achieve multi-thread performance on
        > Windows system?[/color]

        Yeah you're right it's not multi-threading proper, which I have done in .NET
        with both VB and C#. As far as I have been able to determine there is no
        way to do this in PHP other than using process forking. If someone else is
        able to help out here I'd be interested to, although I'm coming from a Unix
        platform not a Windows one.

        Chris

        --
        Chris Hope
        The Electric Toolbox Ltd

        Comment

        • Chung Leong

          #5
          Re: PHP and Multi-thread

          "OutsiderJustic e" <outsiderjustic e@yahoo.com> wrote in message
          news:613e9225.0 404041223.719ea 19d@posting.goo gle.com...[color=blue]
          > Chris Hope <blackhole@elec trictoolbox.com > wrote in message[/color]
          news:<7xObc.480 6$d%6.87672@new s.xtra.co.nz>.. .[color=blue]
          > I'm not a Windows guy, but I believe Windows also has it's own process
          > control APIs, so I'm kind of wondering why this is not implemented on
          > Windows version.
          >
          > Is there anything may be useful to achieve multi-thread performance on
          > Windows system?[/color]

          Take a look at the Win32 extension. In theory you can build a wrapper around
          the W32 API. In practice though, it will probably be very unstable--if it
          works at all.


          Comment

          Working...