2017 © Pedro Peláez
 

library fifo

image

pangou/fifo

  • Sunday, February 14, 2016
  • by chenchun0629
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

a php lib for fifo

单进程, (*1)

<?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();

多进程, (*2)

<?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";
}

阻塞与非阻塞, (*3)

<?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 -> setBlock(1));  // 阻塞
var_dump($read -> read());

The Versions

14/02 2016

dev-master

9999999-dev

  Sources   Download

MIT

by Avatar chenchun0629