ReactPHP FileSystem - No supported adapter found for this installation

262 Views Asked by At

I'm trying to run this simple code on both PHP 7 and 8:

$loop = \React\EventLoop\Factory::create();
$filesystem = \React\Filesystem\Filesystem::create($loop);
$file = $filesystem->file('test.txt');
$file->getContents()->then(function ($contents) {
    echo $contents . PHP_EOL;
});
$loop->run();

After installing via composer, and yet it tells me that adapter is missing

Error:

PHP Fatal error:  Uncaught RuntimeException: No supported adapter found for this installation in \root\src\Filesystem.php:31
Stack trace:
#0 \root\try.php(6): React\Filesystem\Filesystem::create()
#1 {main}
  thrown in \root\vendor\react\filesystem\src\Filesystem.php on line 31
1

There are 1 best solutions below

0
On BEST ANSWER

Just look where and why the exception originated. (I will use react/filesystem:0.1.2 in code examples.)

The exception was thrown in React\Filesystem\Filesystem::create(). List of supported adapters is obtained from React\Filesystem\Filesystem::getSupportedAdapters().

This way you will come to methods which define whether given adapter is available on your platform:

  1. Method Eio\Adapter::isSupported():
    return substr(strtolower(PHP_OS), 0, 3) !== 'win' && function_exists('proc_open');
    This means your platform must not be Windows and proc_open() function must exist (i.e. it must not be disabled for security reasons by disable_functions directive).

  2. Method ChildProcess\Adapter::isSupported():
    return extension_loaded('eio');
    This means eio PHP extension must be installed, see installation instructions.

For me it also does not work as I am on Windows. For development with ReactPHP, it is generally a good idea to run PHP on Linux virtual machine for better compatibility.