Download the PHP package php-io-extensions/fd without Composer
On this page you can find all versions of the php package php-io-extensions/fd. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-io-extensions/fd
More information about php-io-extensions/fd
Files in php-io-extensions/fd
Package fd
Short Description PHP-Controllable UNIX FileDescriptor Extension
License MIT
Informations about the package fd
FD
PHP-controllable UNIX file descriptor extension built with Zephir.
The FD extension allows PHP to open raw UNIX file descriptors, enabling control beyond simple stream-based I/O. The integer descriptor can be passed into other extensions or used directly for system-level interfaces such as GPIO, I2C, SPI, and UART.
Requirements
- PHP 8.x
- A UNIX-like operating system (Linux, macOS)
- Standard C build tools (
gcc,make, PHP development headers)
Installation
Via PHP PIE (recommended)
PHP PIE is the official PHP extension installer. It handles the full build and activation pipeline automatically.
Install PIE if you haven't already:
Then install the extension:
PIE will build the extension from source, copy the .so into PHP's extension directory, and write the ini activation file. No Zephir required — the C source is pre-generated in the package.
Manual installation
Clone the repository and run the bundled installer script. PHP dev headers and gcc must be present; Zephir is not required.
The script builds from the pre-generated C source in ext/, installs the .so, and enables the extension across all detected SAPIs (CLI, FPM, Apache).
Verifying installation
Usage
All methods are static on the Fd\FD class.
Flags
$flags parameters accept plain integers. They map directly to the POSIX constants from fcntl.h — PHP does not define these, so pass the values directly or define your own:
| Constant | Linux | macOS |
|---|---|---|
O_RDONLY |
0 |
0 |
O_WRONLY |
1 |
1 |
O_RDWR |
2 |
2 |
O_NONBLOCK |
2048 |
4 |
Combine multiple flags with the bitwise OR operator (|):
FD::open
Opens a file or device and returns a file descriptor integer.
Returns the file descriptor on success, or a negative value on failure.
FD::close
Closes an open file descriptor.
Returns 0 on success, -1 on failure.
FD::addFlags
Adds file status flags to an open file descriptor using fcntl. Existing flags are preserved; the provided flags are OR'd in.
Returns 0 on success, -1 on failure. Useful for setting a descriptor non-blocking after it has already been opened.
FD::read
Reads up to $bytes_to_read bytes from a file descriptor and returns them as a string.
Returns the bytes read as a binary string. Returns an empty string on error. A zero-length read (e.g. EOF) also returns an empty string, so callers that need to distinguish the two cases should check the descriptor state beforehand.
FD::write
Writes bytes to a file descriptor.
Returns the number of bytes written on success, or -1 on failure.
Example: I2C Read/Write
License
Project Saturn Studios, LLC.