Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a high performance asynchronous socket server application in PHP?
    primarykey
    data
    text
    <p>With nodejs, it's very easy to create a non-blocking TCP server. Example from nodejs.org:</p> <pre><code>var net = require('net'); var server = net.createServer(function (socket) { socket.write("Echo server\r\n"); socket.pipe(socket); }); server.listen(1337, "127.0.0.1") </code></pre> <p>nodejs handles the select()-/poll()-/epoll() stuff for you, the socket routines and the main loop are implemented in C, so it's very fast and efficient.</p> <p>nodejs is great, but I'd like to implement a high performance TCP socket server in PHP, because I'm a PHP guy :)</p> <p>So, one thing I already tried is to implement the socket routines in PHP, with <code>socket_create_listen</code>, <code>socket_accept</code>, <code>socket_select</code> etc. and the main loop in PHP. This works very well, but I don't think it's very efficient, because I have to use <code>socket_select</code> which calls the C-function <code>select</code> internally, but <code>epoll</code> would be better I think (I'm using Linux), but <code>epoll</code> is not available as PHP function. (<a href="http://code.google.com/p/phpsocketdaemon/" rel="noreferrer">phpsocketdaemon</a> and <a href="http://sourceforge.net/projects/phpmio/" rel="noreferrer">phpmio</a> are 2 projects I found that implement the socket-routines for you).</p> <p>Would it be possible to do it the nodejs way? I'm thinking about a PHP module that implements the loop and socket routines in C, and calls PHP callback functions for events (<code>onread</code>, <code>onerror</code>..). Or is it not worth the effort?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload