Click to See Complete Forum and Search --> : [RESOLVED] PHP sockets, multithreading?


MrCoder
01-17-2007, 02:50 PM
I am currently in the process of converting a C# application to PHP.

Within this application I have a multithreaded loop that handles incoming packets.

Since PHP does not support multithreading what would be the best way to handle these packets?

The only thing I have managed to come up with so far is to spwan another PHP script from within the first and write the incoming packets to a database that would be polled by an RPC call every X seconds.

Can this be done using PHP sockets alone?
Will I be able to store the packets within the PHP sockets for an extended amount of time insted of having to write the packets to a database?

Or is there another way?

bokeh
01-17-2007, 03:05 PM
In PHP you can open and read from sockets in non-blocking mode. That means you could open, for example, ten connections in a loop and send a request to each. You could then loop through them every so often (also in non-blocking mode). If you try to read from a socket in non-blocking mode and there is nothing to read at that instant PHP hands control back to the script rather than waiting (indefinately) for the socket to output something.

NightShift58
01-21-2007, 01:27 AM
I've never used it...

but it seems thatdeclare(ticks=1);could give you a bit more (finer) control over the loops and you may not have to spawn out.

MrCoder
01-21-2007, 05:38 AM
I've never used it...

but it seems thatdeclare(ticks=1);could give you a bit more (finer) control over the loops and you may not have to spawn out.

Thats nice to know, thanks!