https://github.com/bandie91/php5-pipe2
wrapper functions for pipe(2) and dup2(2) syscalls
https://github.com/bandie91/php5-pipe2
Last synced: 3 months ago
JSON representation
wrapper functions for pipe(2) and dup2(2) syscalls
- Host: GitHub
- URL: https://github.com/bandie91/php5-pipe2
- Owner: bAndie91
- Created: 2014-07-09T10:19:58.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2025-01-21T06:30:57.000Z (4 months ago)
- Last Synced: 2025-01-21T07:26:46.368Z (4 months ago)
- Language: PHP
- Size: 35.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pipe(2) binding for PHP
It is a PHP extension provides functions for low-level
file descriptor operations:
* ``posix_pipe()`` binds to ``pipe()`` syscall
* ``posix_dup2()`` binds to ``dup2()`` syscall
* ``posix_close()`` binds to ``close()`` syscall# Have you ever wondered how to do cheap forking and running subprocesses?
PHP already provides ``exec()``, ``system()`` and ``proc_open()`` to
run a child process, but with not as little overhead as possible.
``exec()``, ``system()`` and ``proc_open()`` spawns shell first.You can use **pcntl** family to build a low cost exec function.
*However pcntl is not available in all SAPI.*
You will need ``pcntl_fork()`` and ``pcntl_exec()`` then ``pcntl_waitpid()``
to implement a subprocess executing function.
In this case you lose the child process' output, stderr and the ability
to pipe data into its stdin, which is built in ``proc_open()`` by default
and partially in ``exec()`` (only stdout is captured).A possible low-level solution is to request pipes from the OS and
redirecting them in the child process before exec'ing.
This module provides bindings to POSIX API functions suitable for this job.# Usage
``array posix_pipe()``
Returns an array holding stream resources for the new
pipe's reader and writer end, and their file descriptors.
```
[0] => stream reader,
[1] => stream writer,
[2] => int reader_fd,
[3] => int writer_fd,
```
``bool posix_dup2(mixed oldfd, mixed newfd)``
oldfd and newfd can be stream type resources or int.
Returns TRUE if success, FALSE otherwise.
``bool posix_close(int fd)``
Returns TRUE if success, FALSE otherwise.# Example
see example.php# Project issues, bugs, feature requests, ideas
1. clone the repo
2. use [git-bug](https://github.com/git-bug/git-bug) to open a new ticket in this repo
3. find one or more person in the commit history to make contact with, then either
4.a. send your newly created `git-bug` ticket (or patch if you already propose a code change) via email, or
4.b. send the URL of your git clone to a contributor (via email or other channel), and request them to pull (`git-bug` issues and/or branches as well) from you.