PHPackages                             rask/libload - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rask/libload

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rask/libload
============

A small FFI library loader tool

0.2.1(6y ago)781[2 issues](https://github.com/rask/php-libload/issues)MITPHPPHP &gt;=7.4CI failing

Since Feb 13Pushed 6y ago1 watchersCompare

[ Source](https://github.com/rask/php-libload)[ Packagist](https://packagist.org/packages/rask/libload)[ RSS](/packages/rask-libload/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (12)Versions (5)Used By (0)

rask/libload
============

[](#rasklibload)

[![Latest Stable Version](https://camo.githubusercontent.com/ac26802facc04ae31e1f6b584572df06a6f4f63a598219193c113ef2c2894156/68747470733a2f2f706f7365722e707567782e6f72672f7261736b2f6c69626c6f61642f762f737461626c65)](https://packagist.org/packages/rask/libload) [![Infection MSI](https://camo.githubusercontent.com/963a666e3532ad87c3d9e3cb1db9283294e1833f437c84ebff13d0f3af68bab5/68747470733a2f2f62616467652e737472796b65722d6d757461746f722e696f2f6769746875622e636f6d2f7261736b2f7068702d6c69626c6f61642f6d6173746572)](https://infection.github.io)

A small library to help in loading FFI libraries in a straight-forward manner.

Rationale
---------

[](#rationale)

The vanilla methods of loading dynamic libraries via PHP FFI are simple and understandable:

- `\FFI::cdef()` allows you to take in a library, and write the library header definition on the fly.
- `\FFI::load()` allows you to take in a library header, inside which resides `FFI_LIB` that points to a dynamic library to load.

This is all fine and well, apart from one thing:

You're locked tight into the logic of `dlopen(3)`, which is a C function to load dynamic libraries. In essence this means the following:

1. You cannot use relative paths for `FFI_LIB`, as those operate on current working directory, which can be whatever
2. You cannot use absolute paths, as all software is runnable anywhere on any system in any path
3. You cannot rely on `LD_LIBRARY_PATH` as it cannot be altered at runtime, and you would require users of your code to set it up properly
4. You cannot use `/lib` or `/usr/lib`, as that would be senseless pollution on the user's system, not to speak of requiring admin privileges

In smaller projects with limited audiences these limitations might not matter. Or maybe the library you intend to use is a well-known and often preinstalled one (e.g. `libc`). But once you want to distribute public code that relies on a custom built FFI library, you're in trouble.

So, the only real reason this library exists is to bypass these limitations, and allow you to load a dynamic library in a few different ways.

Features
--------

[](#features)

- Load libraries the `dlopen(3)` way
- Load libraries relative to the header file
- Load libraries relative to a custom path
- Load libraries by searching for them inside a directory tree

Example
-------

[](#example)

```
