I wonder what is the fastest way to send data from one process to another in PHP? Data is just a short string. Curretly I have a solution with AF_UNIX sockets, but tests show that it takes 0.100 ms to transfer data from one process to another. I wonder if shared memory could be faster? However, I have no idea how to get another process to regularly check the shared memory for detection if there is any new data?
Current solution:
$server = socket_create(AF_UNIX, SOCK_STREAM, 0); socket_bind($server, '/tmp/mysock'); socket_listen($server); while(true) { $r = $clients; if(socket_select($r, $w, $e, 5) > 0) { $client = socket_accept($server); $d = trim(socket_read($client, 256, PHP_NORMAL_READ)); echo (microtime(true)-$d)."\n"; socket_close($client); } flush(); } socket_close($server);
And the client:
$d = microtime(true)."\n"; $socket = socket_create(AF_UNIX, SOCK_STREAM, 0); socket_connect($socket, '/tmp/mysock'); socket_write($socket, $d, strlen($d)); socket_close($socket);
This solution works completely fine, but the results look like this:
0.00019216537475586 9.5129013061523E-5 0.00011920928955078 0.00011801719665527 7.6055526733398E-5
Any ideas how to make this script faster or develop a faster (possibly shared memory) solution?
Thanks in advance, Jonas
php shared-memory stream sockets ipc
flyeris
source share