首页 > 解决方案 > Linux中的Rachet和命名管道

问题描述

我正在使用 Rachet 创建套接字,其中一种更新方法是写入命名管道 ( mkfifo filename)

下面的代码有效

$server = IoServer::factory(
$application = new WebSocketApplication(),
8080
);
$updateFile = fopen('/tmp/testing', 'r');

$update = function ($stream) use ($application, $server, $u) {
    $value = fread($stream, 8219);
    $application->update($value);
    //the line below is magic apparently, if this is removed, I end up in an infinite loop
    fopen('/tmp/testing', 'r');
};
$server->loop->addReadStream($updateFile, $update);

$server->run();

这完全符合预期。我不知道为什么我需要第二条 fopen 线。

有人可以解释为什么需要它或者我做错了什么甚至需要这条线。

标签: phpnamed-pipesratchet

解决方案


推荐阅读