Implementing pThreads

Discussion in 'PHP' started by jimmybrion, Dec 13, 2012.

  1. #1
    Anybody around who already has some experience with pThreads ? I'm interested in implementing a multi threaded socket server...
     
    jimmybrion, Dec 13, 2012 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    It is not a hard thing to do. I recently made an implementation in c, it should be much easier in PHP.

    You basically create, bind, and listen to all new connections and fork a new thread for each request.

    Look at the following pages then let us know if you need any help.

    http://php.net/manual/en/ref.sockets.php

    http://php.net/manual/en/function.pcntl-fork.php

    You can view a sample demo in C (you can convert the logic to PHP with the above two references):

    http://www.linuxhowtos.org/C_C++/socket.htm
     
    ThePHPMaster, Dec 15, 2012 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    @ThePHPMaster -- I don't think that's what's being asked... since it's in the PHP section, the OP is probably asking about the actual PHP pThreads object and it's descendents, with it's effectively nonexistent documentation and complete lack of examples anywhere online that I can find on what to do with it.
     
    deathshadow, Dec 15, 2012 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    Thanks for the link. I didn't notice PHP having a future feature to implement Threads.

    I guess this is a question for the OP, are you building your own PHP or using an existing release. If you want to use the pThreads above, I would suggests you wait until development process on it is complete, once it is implemented into a stable PHP release, it will be documented with examples, I hope.
     
    ThePHPMaster, Dec 16, 2012 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #5
    krakjoe, Jan 8, 2013 IP