<?php require __DIR__ . '/../vendor/autoload.php'; $pid = pcntl_fork(); if ($pid == -1) { exit('fork error'); } else { if ($pid == 0) { # child $protocol = new Pangou\Fifo\Protocol\LengthProtocol(); $read = new Pangou\Fifo\Fifo($protocol, '/tmp/serv.fifo', '0666', true); echo $read->read(), "\n"; echo "child over\n"; } else { if ($pid > 0) { # parent $protocol = new Pangou\Fifo\Protocol\LengthProtocol(); $write = new Pangou\Fifo\Fifo($protocol, '/tmp/serv.fifo', '0666', false); $write->write('hello, fifo'); pcntl_wait($status); echo "parent over\n"; } } }
<?php require __DIR__ . '/../vendor/autoload.php'; $protocol = new Pangou\Fifo\Protocol\LengthProtocol(); $write = new Pangou\Fifo\Fifo($protocol, '/tmp/serv.fifo', '0666', false); $read = new Pangou\Fifo\Fifo($protocol, '/tmp/serv.fifo', '0666', true); var_dump($read->setBlock(0)); var_dump($read->read());
<?php require __DIR__ . '/../vendor/autoload.php'; $protocol = new Pangou\Fifo\Protocol\LengthProtocol(); $write = new Pangou\Fifo\Fifo($protocol, '/tmp/serv.fifo', '0666', false); $read = new Pangou\Fifo\Fifo($protocol, '/tmp/serv.fifo', '0666', true); $write->write('hello, fifo!!!'); echo $read->read();
<?php require __DIR__ . '/../vendor/autoload.php'; $protocol = new Pangou\Fifo\Protocol\LengthProtocol(); $write = new Pangou\Fifo\Fifo($protocol, '/tmp/serv.fifo', '0666', false); $read = new Pangou\Fifo\Fifo($protocol, '/tmp/serv.fifo', '0666', true); $a = microtime(true); $str = str_pad('a', 16); $len = 0; for ($i = 0; $i <= 100000; $i++) { // echo $len += strlen($str), " i = ", $i, "\n"; $write->write($str); $read->read(); } $b = microtime(true); echo $b - $a; // echo $read -> read();