Example #1
1
 /**
  * Constructor.
  * @param string $filePath The file that is going to store the pipe.
  * @param bool $isReadMode Indicates if the param is going to be read only
  * @param bool $autoDeletion If it is set during the destruction of the GPhpThreadIntercom instance the pipe file will be also removed.
  */
 public function __construct($filePath, $isReadMode = true, $autoDeletion = false)
 {
     // {{{
     $this->ownerPid = getmypid();
     if (!file_exists($filePath)) {
         if (!posix_mkfifo($filePath, 0644)) {
             $this->success = false;
             return;
         }
     }
     $commChanFd = fopen($filePath, $isReadMode ? 'r+' : 'w+');
     // + mode makes it non blocking too
     if ($commChanFd === false) {
         $this->success = false;
         return;
     }
     if (!stream_set_blocking($commChanFd, false)) {
         $this->success = false;
         fclose($commChanFd);
         if ($autoDeletion) {
             @unlink($filePath);
         }
         return;
     }
     $this->commChanFdArr[] = $commChanFd;
     $this->commFilePath = $filePath;
     $this->autoDeletion = $autoDeletion;
     $this->isReadMode = $isReadMode;
 }
 public function __construct($name, $read_cb = null)
 {
     $pipes_folder = JAXL_CWD . '/.jaxl/pipes';
     if (!is_dir($pipes_folder)) {
         mkdir($pipes_folder);
     }
     $this->ev = new JAXLEvent();
     $this->name = $name;
     $this->read_cb = $read_cb;
     $pipe_path = $this->get_pipe_file_path();
     if (!file_exists($pipe_path)) {
         posix_mkfifo($pipe_path, $this->perm);
         $this->fd = fopen($pipe_path, 'r+');
         if (!$this->fd) {
             _error("unable to open pipe");
         } else {
             _debug("pipe opened using path {$pipe_path}");
             _notice("Usage: \$ echo 'Hello World!' > {$pipe_path}");
             $this->client = new JAXLSocketClient();
             $this->client->connect($this->fd);
             $this->client->set_callback(array(&$this, 'on_data'));
         }
     } else {
         _error("pipe with name {$name} already exists");
     }
 }
Example #3
0
 /**
  * @param string $name
  * @param callable $read_cb TODO: Currently not used
  */
 public function __construct($name, $read_cb = null)
 {
     // TODO: see JAXL->cfg['priv_dir']
     $this->pipes_folder = getcwd() . '/.jaxl/pipes';
     if (!is_dir($this->pipes_folder)) {
         mkdir($this->pipes_folder, 0777, true);
     }
     $this->ev = new JAXLEvent();
     $this->name = $name;
     // TODO: If someone's need the read callback and extends the JAXLPipe
     // to obtain it, one can't because this property is private.
     $this->read_cb = $read_cb;
     $pipe_path = $this->get_pipe_file_path();
     if (!file_exists($pipe_path)) {
         posix_mkfifo($pipe_path, $this->perm);
         $this->fd = fopen($pipe_path, 'r+');
         if (!$this->fd) {
             JAXLLogger::error("unable to open pipe");
         } else {
             JAXLLogger::debug("pipe opened using path {$pipe_path}");
             JAXLLogger::notice("Usage: \$ echo 'Hello World!' > {$pipe_path}");
             $this->client = new JAXLSocketClient();
             $this->client->connect($this->fd);
             $this->client->set_callback(array(&$this, 'on_data'));
         }
     } else {
         JAXLLogger::error("pipe with name {$name} already exists");
     }
 }
Example #4
0
 public function __construct($file)
 {
     $this->file = $file;
     if (!file_exists($file)) {
         posix_mkfifo($file, 0700);
     }
 }
Example #5
0
File: Fifo.php Project: gcds/morker
 /**
  * Constructor.
  *
  * @param Master  $master The master object
  * @param integer $pid    The child process id or null if this is the child
  *
  * @throws \Exception
  * @throws \RuntimeException
  */
 public function __construct(Master $master, $pid = null)
 {
     $this->master = $master;
     $directions = array('up', 'down');
     if (null === $pid) {
         // child
         $pid = posix_getpid();
         $pPid = posix_getppid();
         $modes = array('write', 'read');
     } else {
         // parent
         $pPid = null;
         $modes = array('read', 'write');
     }
     $this->pid = $pid;
     $this->ppid = $pPid;
     foreach (array_combine($directions, $modes) as $direction => $mode) {
         $fifo = $this->getPath($direction);
         if (!file_exists($fifo) && !posix_mkfifo($fifo, 0600) && 17 !== ($error = posix_get_last_error())) {
             throw new \Exception(sprintf('Error while creating FIFO: %s (%d)', posix_strerror($error), $error));
         }
         $this->{$mode} = fopen($fifo, $mode[0]);
         if (false === ($this->{$mode} = fopen($fifo, $mode[0]))) {
             throw new \RuntimeException(sprintf('Unable to open %s FIFO.', $mode));
         }
     }
 }
Example #6
0
 public function open($fifoFile)
 {
     $this->fifoFile = $fifoFile;
     $dir = pathinfo($this->fifoFile, PATHINFO_DIRNAME);
     umask(0);
     $this->selfCreated = false;
     if (!is_dir($dir)) {
         if (!mkdir($dir, 0777, true)) {
             throw new \Exception("Could not create directory {$dir}");
         }
     }
     // If pipe was not create on another side
     if (!file_exists($this->fifoFile)) {
         if (!posix_mkfifo($this->fifoFile, 0777)) {
             throw new \Exception("Could not create {$this->fifoFile}: " . posix_strerror(posix_get_last_error()));
         } else {
             $this->selfCreated = true;
         }
     }
     log::debug("Creating stream for {$this->fifoFile}");
     $stream = fopen($this->fifoFile, "c+");
     log::debug("Stream {$stream} = {$this->fifoFile}");
     $this->valid = (bool) $stream;
     parent::open($stream);
     $this->setBlocking(false);
 }
Example #7
0
 /**
  * Create the file if needed
  *
  * @return Pipe
  */
 public function create()
 {
     if (!is_file($this->name)) {
         return;
     }
     posix_mkfifo($this->name, 0777);
     return $this;
 }
Example #8
0
 static function init_pipes()
 {
     for ($i = 1; $i <= Config::$queue_number; $i++) {
         $queue_file = Config::$queue_dir . "/websnap_queue_{$i}";
         if (!file_exists($queue_file)) {
             posix_mkfifo($queue_file, 0644);
         }
     }
 }
Example #9
0
 public function __construct($pathname, $mod = 0660)
 {
     if (!is_file($pathname)) {
         if (!posix_mkfifo($pathname, $mod)) {
             // throw
         }
     }
     $this->pathname = $pathname;
 }
Example #10
0
 /**
  * @param string $filename fifo filename
  * @param int $mode
  * @param bool $block if blocking
  */
 public function __construct($filename = '/tmp/simple-fork.pipe', $mode = 0666, $block = false)
 {
     if (!file_exists($filename) && !posix_mkfifo($filename, $mode)) {
         throw new \RuntimeException("create pipe failed");
     }
     if (filetype($filename) != "fifo") {
         throw new \RuntimeException("file exists and it is not a fifo file");
     }
     $this->filename = $filename;
     $this->block = $block;
 }
Example #11
0
 public function __construct($port = 4444, $address = '127.0.0.1')
 {
     parent::__construct($port, $address);
     $this->pid = posix_getpid();
     if (!file_exists(self::PIPENAME)) {
         umask(0);
         if (!posix_mkfifo(self::PIPENAME, 0666)) {
             die('Cant create a pipe: "' . self::PIPENAME . '"');
         }
     }
     $this->pipe = fopen(self::PIPENAME, 'r+');
 }
Example #12
0
 /**
  * Create a new pipeline.
  */
 public function __construct()
 {
     $tmp_path = tempnam(sys_get_temp_dir(), "spawn.");
     // Initialise FIFO pipes.
     $this->request_path = $tmp_path . '.i';
     $this->response_path = $tmp_path . '.o';
     if (!file_exists($this->request_path)) {
         posix_mkfifo($this->request_path, 0644);
     }
     if (!file_exists($this->response_path)) {
         posix_mkfifo($this->response_path, 0644);
     }
 }
 public function createStream()
 {
     if ('Linux' !== PHP_OS) {
         return parent::createStream();
     }
     $this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
     unlink($this->fifoPath);
     // Use a FIFO on linux to get around lack of support for disk-based file
     // descriptors when using the EPOLL back-end.
     posix_mkfifo($this->fifoPath, 0600);
     $stream = fopen($this->fifoPath, 'r+');
     return $stream;
 }
Example #14
0
 /**
  * 创建fifo
  * @return [type] [description]
  */
 protected function createFifo()
 {
     if (file_exists($this->name) && filetype($this->name) != 'fifo') {
         copy($this->name, $this->name . '.backup');
         unlink($this->name);
     }
     if (!file_exists($this->name) && true !== posix_mkfifo($this->name, $this->mode)) {
         throw new \Exception('create fifo fail');
     }
     if (filetype($this->name) != 'fifo') {
         throw new \Exception('fifo type error');
     }
 }
Example #15
0
 /** Initialize the named pipe
 		@param pipefile	Name of the new named pipe to create
 		@param mode	Numeric permission indicator for the new pipe
 	*/
 function _pipeInit($pipefile, $mode)
 {
     if (!file_exists($pipefile)) {
         // create the pipe
         umask(0);
         posix_mkfifo($pipefile, $mode);
     }
     // save the pipe to instance var
     $this->pipe = fopen($pipefile, "r+");
     // turn off blocking
     stream_set_blocking($this->pipe, 0);
     //fwrite($this->pipe, "cfDebug Init\n\n");
 }
 function __construct($fifoPath, $mode = 0666)
 {
     //posix_getpid 返回进程ID号
     // $fifoPath = "/home//$name.".posix_getpid();
     if (!file_exists($fifoPath)) {
         if (!posix_mkfifo($fifoPath, $mode)) {
             error('create new pipe ($name) error.');
             return false;
         }
     } else {
         error("pipe ({$name}) has exist.");
         return false;
     }
     $this->fifoPath = $fifoPath;
 }
Example #17
0
 public function __construct($file, $create = true)
 {
     $this->file = $file;
     if (!$this->exists() && $create) {
         touch($this->file);
         posix_mkfifo($this->file, 0666);
         $this->creator = true;
         $this->fh = fopen($this->file, "r+");
     } else {
         if ($this->exists()) {
             $this->fh = fopen($this->file, "r+");
         } else {
             throw new \Exception("Could not open FIFO for reading: Node does not exist.");
         }
     }
     stream_set_blocking($this->fh, 0);
 }
Example #18
0
 public function __construct($name, $perm = 0600)
 {
     $this->name = $name;
     $this->perm = $perm;
     $pipe_path = $this->get_pipe_file_path();
     if (!file_exists($pipe_path)) {
         posix_mkfifo($pipe_path, $this->perm);
         $this->fd = fopen($pipe_path, 'r+');
         if (!$this->fd) {
             _error("unable to open pipe");
         }
         stream_set_blocking($this->fd, false);
         // watch for incoming data on pipe
         JAXLLoop::watch($this->fd, array('read' => array(&$this, 'on_read_ready')));
     } else {
         _error("pipe with name {$name} already exists");
     }
 }
Example #19
0
 /**
  * Runs the command and returns the command output and the separated STDERR in the outgoing parameter.
  *
  * Uses the "system.commandOutputHelper.work.path" config, what is describes the directory where the temporary
  * file pointer will be added. (default => /tmp)
  *
  * @param CommandExecutor $command   The command executor object.
  * @param string          $stdErr    The error messages [Outgoing]
  *
  * @return \YapepBase\Shell\CommandOutput   The output of the command.
  * @throws \Exception
  */
 public function runCommandWithStdErr(CommandExecutor $command, &$stdErr)
 {
     $dir = Config::getInstance()->get('system.commandOutputHelper.work.path', '/tmp');
     $pipePath = tempnam($dir, 'stderr-');
     $fileHandler = Application::getInstance()->getDiContainer()->getFileHandler();
     try {
         posix_mkfifo($pipePath, 0755);
         $command->setOutputRedirection(CommandExecutor::OUTPUT_REDIRECT_STDERR, $pipePath);
         $result = $command->run();
         $stdErr = $fileHandler->getAsString($pipePath);
         $fileHandler->remove($pipePath);
     } catch (\Exception $e) {
         if ($fileHandler->checkIsPathExists($pipePath)) {
             $fileHandler->remove($pipePath);
         }
         throw $e;
     }
     return $result;
 }
Example #20
0
 /**
  * Ensure the fifo is created.
  */
 private function ensureFifo()
 {
     if (file_exists($this->fileName)) {
         $type = filetype($this->fileName);
         if ($type != "fifo") {
             throw new Exception("File already exists, but it is not a fifo");
         }
         return;
     }
     if (function_exists("posix_mkfifo")) {
         if (!posix_mkfifo($this->fileName, 0644)) {
             throw new Exception("Unable to create fifo using posix_mkfifo");
         }
         return;
     }
     exec("/usr/bin/mkfifo " . escapeshellarg($this->fileName), $ret, $err);
     if ($err) {
         throw new Exception("Unable to create fifo using exec(mkfifo)");
     }
 }
Example #21
0
 /**
  * 解析 autoload_classmap.php 生成类的继承关系和接口的实现关系
  *
  * @param bool $is_force 是否强制重新刷新索引
  */
 public function index($is_force = false)
 {
     if (is_dir($this->getIndexDir()) && !$is_force) {
         return;
     }
     $this->initIndexDir();
     exec('composer dump-autoload -o -d ' . $this->root);
     $this->class_map = (require $this->class_map_file);
     $pipe_path = sys_get_temp_dir() . '/' . uniqid();
     posix_mkfifo($pipe_path, 0600);
     $class_num = count($this->class_map);
     $cmd = 'let g:pb = vim#widgets#progressbar#NewSimpleProgressBar("Indexing:", ' . $class_num . ')';
     $this->callRpc('vim_command', $cmd);
     while ($this->class_map) {
         $pid = pcntl_fork();
         if ($pid == -1) {
             die('could not fork');
         } elseif ($pid > 0) {
             // 父进程
             $pipe = fopen($pipe_path, 'r');
             $data = fgets($pipe);
             $this->class_map = json_decode(trim($data), true);
             pcntl_waitpid($pid, $status);
         } else {
             // 子进程
             $pipe = fopen($pipe_path, 'w');
             register_shutdown_function(function () use($pipe) {
                 $data = json_encode($this->class_map, true);
                 fwrite($pipe, "{$data}\n");
                 fclose($pipe);
             });
             $this->_index();
             fwrite($pipe, "[]\n");
             fclose($pipe);
             exit;
         }
     }
     fclose($pipe);
     unlink($pipe_path);
     $this->callRpc('vim_command', 'call g:pb.restore()');
 }
Example #22
0
 /**
  * Fetch and save class's interface and parent info
  * according the autoload_classmap.php file
  *
  * @param bool $is_force overwrite the exists index
  */
 public function index($is_force = false)
 {
     if (is_dir($this->getIndexDir()) && !$is_force) {
         return;
     }
     $this->initIndexDir();
     exec('composer dump-autoload -o -d ' . $this->root . ' 2>&1 >/dev/null');
     $this->class_map = (require $this->root . '/vendor/composer/autoload_classmap.php');
     $pipe_path = sys_get_temp_dir() . '/' . uniqid();
     posix_mkfifo($pipe_path, 0600);
     $this->vimOpenProgressBar(count($this->class_map));
     while ($this->class_map) {
         $pid = pcntl_fork();
         if ($pid == -1) {
             die('could not fork');
         } elseif ($pid > 0) {
             // 父进程
             $pipe = fopen($pipe_path, 'r');
             $data = fgets($pipe);
             $this->class_map = json_decode(trim($data), true);
             pcntl_waitpid($pid, $status);
         } else {
             // 子进程
             $pipe = fopen($pipe_path, 'w');
             register_shutdown_function(function () use($pipe) {
                 $data = json_encode($this->class_map, true);
                 fwrite($pipe, "{$data}\n");
                 fclose($pipe);
             });
             $this->_index();
             fwrite($pipe, "[]\n");
             fclose($pipe);
             exit;
         }
     }
     fclose($pipe);
     unlink($pipe_path);
     $this->vimCloseProgressBar();
 }
Example #23
0
 public function createStream()
 {
     // Use a FIFO on linux to get around lack of support for disk-based file
     // descriptors when using the EPOLL back-end.
     if ('Linux' === PHP_OS) {
         $this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
         unlink($this->fifoPath);
         posix_mkfifo($this->fifoPath, 0600);
         $stream = fopen($this->fifoPath, 'r+');
         // ext-event (as of 1.8.1) does not yet support in-memory temporary
         // streams. Setting maxmemory:0 and performing a write forces PHP to
         // back this temporary stream with a real file.
         //
         // This problem is mentioned at https://bugs.php.net/bug.php?id=64652&edit=3
         // but remains unresolved (despite that issue being closed).
     } else {
         $stream = fopen('php://temp/maxmemory:0', 'r+');
         fwrite($stream, 'x');
         ftruncate($stream, 0);
     }
     return $stream;
 }
Example #24
0
function faceForIDs($ids)
{
    if (!is_array($ids)) {
        $ids = array($ids);
    }
    $transfer = array('ids' => $ids);
    $jsonTransfer = json_encode($transfer);
    // #input pipe
    // $pipe_in ="/tmp/pipe_faceIDs_back";
    // if(!file_exists($pipe_in)){
    // umask(0);
    // posix_mkfifo( $pipe, 0666 );
    // }
    #input pipe
    $pipe_out = "/tmp/pipe_faceIDs";
    if (!file_exists($pipe_out)) {
        umask(0);
        posix_mkfifo($pipe, 0666);
    }
    $handle = fopen("/tmp/pipe_faceIDs", "w");
    fwrite($handle, $jsonTransfer);
    fclose($handle);
}
Example #25
0
 /**
  * check, create and validate the fifo file/folder
  *
  * @param string        $file
  * @param string|null   $folder
  *
  * @throws TransportException
  */
 protected function intializeFile($file, $folder = null)
 {
     if (is_null($folder)) {
         $folder = sys_get_temp_dir();
     }
     if (!is_dir($folder)) {
         if (false === mkdir($folder, 0777, true)) {
             throw TransportException::couldNotCreateFolder($folder);
         }
     }
     if (strrev($folder)[0] === '/') {
         $folder = substr($folder, 0, -1);
     }
     $this->fifo = sprintf('%s/%s', $folder, $file);
     if (!file_exists($this->fifo)) {
         if (false === posix_mkfifo($this->fifo, 0600)) {
             throw TransportException::posixError();
         }
     }
     if (false == (stat($this->fifo)['mode'] & 010000)) {
         throw TransportException::fileIsNotANamedPipe($this->fifo);
     }
 }
function play($file, $viddir)
{
    $err = '';
    exec('pgrep omxplayer', $pids);
    //omxplayer is running?
    if (empty($pids)) {
        //NO
        @unlink(FIFO);
        posix_mkfifo(FIFO, 0777);
        chmod(FIFO, 0777);
        // Update Status file to PLAYING
        $statfd = fopen(STATFILE, "w");
        fwrite($statfd, "PLAYING\n");
        fclose($statfd);
        //  Run omx_play.sh with arguments
        shell_exec(getcwd() . '/omx_play.sh ' . escapeshellarg($file) . ' ' . escapeshellarg($viddir));
        $out = 'playing ' . basename($file);
    } else {
        //YES
        $out = '';
        $err = 'omxplayer is already runnning';
    }
    return array('res' => $out, 'err' => $err);
}
Example #27
0
 /**
  * setupPipeFile : setup the file pipe (removing the old one)
  * 
  * @param mixed $_pipe_file 
  * @return php file handler
  */
 public function setupPipeFile($_pipe_file)
 {
     if (file_exists($_pipe_file)) {
         if (!unlink($_pipe_file)) {
             die('unable to remove stale file');
         }
     }
     umask(0);
     if (!posix_mkfifo($_pipe_file, $this->pipe_permissions_octal)) {
         die('unable to create named pipe');
     }
     if ($this->pipe_owning_user != NULL) {
         chown($_pipe_file, $this->pipe_owning_user);
     }
     if ($this->pipe_owning_group != NULL) {
         chgrp($_pipe_file, $this->pipe_owning_group);
     }
     $pipe = fopen($_pipe_file, 'r+');
     if (!$pipe) {
         die('unable to open the named pipe');
     }
     stream_set_blocking($pipe, false);
     return $pipe;
 }
Example #28
0
VERIFY(posix_getpgrp());
VERIFY(posix_getpid());
VERIFY(posix_getppid());
$ret = posix_getpwnam("root");
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VS(posix_getpwnam(""), false);
VS(posix_getpwnam(-1), false);
$ret = posix_getpwuid(0);
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VS(posix_getpwuid(-1), false);
$ret = posix_getrlimit();
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VERIFY(posix_getsid(posix_getpid()));
$tmpfifo = tempnam('/tmp', 'vmmkfifotest');
unlink($tmpfifo);
VERIFY(posix_mkfifo($tmpfifo, 0));
$tmpnod = tempnam('/tmp', 'vmmknodtest');
unlink($tmpnod);
VERIFY(posix_mknod($tmpnod, 0));
VERIFY(posix_setpgid(0, 0));
VERIFY(posix_setsid());
VERIFY(strlen(posix_strerror(1)));
$ret = posix_times();
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
$ret = posix_uname();
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
Example #29
0
unset($opts[CURLOPT_POSTFIELDS]);
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
curl_close($ch);
//Get playlist file from webpage
$result = preg_match("/PARAM NAME=\"FileName\" VALUE=\"(.*)\"/", $result, $matches);
//Download playlist file
$ch = curl_init($matches[1]);
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
curl_close($ch);
//Find stream
$result = preg_match("/Ref href=\"(.*)\"/", $result, $matches);
//Change transport from mms to http
$url = preg_replace("/mms:/", "http:", $matches[1]);
//FIFO from mplayer to lame
$wav_file = "/tmp/xms_streaming" . posix_getpid() . ".wav";
posix_mkfifo($wav_file, 0666);
$descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", "/tmp/error-output.txt", "a"));
//Start mplayer
$handle = proc_open($XMSTREAM_MPLAYER . " -quiet -really-quiet  -vc null -vo null -ao pcm:file={$wav_file} {$url} ", $descriptorspec, $pipes);
//Start lame
$handle2 = proc_open($XMSTREAM_LAME . " {$wav_file} - ", $descriptorspec, $pipes2);
$file2 = $pipes2[1];
while (1) {
    $data = fread($file2, 1024);
    if ($data === FALSE) {
        exit;
    }
    echo $data;
}
Example #30
0
 public static function start_new($wid, $test_id, $debug = false)
 {
     $session = new TestSession();
     $session->Test_id = $test_id;
     $session->debug = $debug ? 1 : 0;
     $session->UserWorkspace_id = $wid;
     $lid = $session->mysql_save();
     $session = TestSession::from_mysql_id($lid);
     if (!$debug) {
         $sql = sprintf("UPDATE `%s` SET `session_count`=`session_count`+1 WHERE `%s`.`id`=%d", Test::get_mysql_table(), Test::get_mysql_table(), $test_id);
         mysql_query($sql);
     }
     $test = $session->get_Test();
     if ($test != null) {
         posix_mkfifo($session->get_RSession_fifo_path(), 0774);
     }
     if ($debug) {
         $session->register();
     }
     return $session;
 }