SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2001
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    multiple sockets in 1 loop : possible ?

    Hello, I've been playing around with sockets a bit. It never used to work before but now I've got a few things going well. But I'm stuck at a script that has several sockets connections, each of them seems to work fine seperated but the combined script never works. So a simple question : is it possible in php to have several socket connections at the same time and use them like you want ?


    the script is a bit like this : (its a bit of a mess, pasting it directly would not be much helpfull, would need to clean it up first)

    PHP Code:
    open connection1 with fsockopen
    open connection2 with socket_create 
    and socket_bind

    while (connection1) {

        
    listen to connection2
        
    if connection2 reads somethingperform specific command

        listen to connection1
        
    do some calculations with the input of connection1
        send something to connection1

        
    do something to keep connection1 up
    }
    close connection2 
    Connection1 is the main purpose of this script, it should listen for a long time and log a lot of things. Connection2 is from another php script, and basicly is a kind of monitoring/control panel. So it should send some commands through so that different kind of things could be logged from connection1 whenever needed. And the reason I do it like this, is that the while loop could last a long time and it will only directly show the results when the loop is finished.... but I want to interact with it while it is still looping. So therefore the two connections.

    The script above works, but only if I leave out everything from connection2. So therefore I assume it would not be wise to mix more then one socket connection in the same script? yes/no ?

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing your sockets are blocking, therefore accept() freezes the whole application. Try using non-blocking sockets.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •