filesystem
filesystem copied to clipboard
PHP-FPM compatibility
Hi,
I'm stacked at situation where I can't use this beautiful library.
I have PHP 7.0.32 with php-fpm enabled. Here is additional information about extensions directly from phpinfo:
// PHP libuv Extension libuv Support enabled Version 0.2.2 libuv Version 1.26
// eio eio support enabled Debug support disabled Version 2.0.4
// event Event support enabled Sockets support enabled Debug support disabled Extra functionality support including HTTP, DNS, and RPC enabled OpenSSL support enabled Thread safety support disabled Extension version 2.4.2 libevent2 headers version 2.0.19-stable
// libevent libevent support enabled extension version 0.2.0-dev Revision $Revision$ libevent version 2.1.8-stable
Here is the code I'm using:
<?php
require __DIR__ . '/vendor/autoload.php';
$loop = \React\EventLoop\Factory::create();
// I tried various loop implementations, but all next produce 'Timed out after 15 seconds' error message
//
//$loop = new \React\EventLoop\ExtUvLoop();
//$loop = new \React\EventLoop\StreamSelectLoop();
//$loop = new \React\EventLoop\ExtEventLoop();
// This loop implementations doesn't work at all
//
//$loop = new \React\EventLoop\ExtEvLoop();// Class 'EvLoop' not found
//$loop = new \React\EventLoop\ExtLibevLoop();// Fatal error: Uncaught BadMethodCallException: Cannot create ExtLibevLoop, ext-libev extension missing
//$loop = new \React\EventLoop\ExtLibeventLoop();// 502
// With default adapter it hangs forever
//
//$filesystem = \React\Filesystem\Filesystem::create($loop);
// With this adapter it produce 'Timed out after 15 seconds' error message
$adapter = new \React\Filesystem\ChildProcess\Adapter($loop);
$filesystem = \React\Filesystem\Filesystem::createFromAdapter($adapter);
echo 'Using ', get_class($filesystem->getAdapter()), '<br/>';
$filename = __DIR__ . '/test_putcontents.txt';
$contents = 'contents';
$filesystem->file($filename)
->putContents($contents)
->then(
function () use ($filename)
{
echo "filename {$filename} written<br/>";
},
function (Exception $e)
{
echo $e->getMessage() . '<br/>';
echo $e->getTraceAsString() . '<br/>';
}
)
->done(
function($someValue)
{
$error_or_not = "error_or_not resolved with someValue: {$someValue}<br/>";
echo $error_or_not."<br/>";
},
function($someReason) use ($filename)
{
$error_or_not = "error_or_not rejected with someReason: {$someReason}<br/>";
echo $error_or_not."<br/>";
}
);
$loop->run();
?>
Here are my results with various loop implementations
Using React\Filesystem\ChildProcess\Adapter
Timed out after 15 seconds
#0 /var/www/user/data/www/vendor/react/event-loop/src/ExtUvLoop.php(119): React\Promise\Timer\{closure}(Object(React\EventLoop\Timer\Timer)) #1 [internal function]: React\EventLoop\ExtUvLoop->React\EventLoop\{closure}(Object(UVTimer)) #2 /var/www/user/data/www/vendor/react/event-loop/src/ExtUvLoop.php(230): uv_run(Object(UVLoop), 1) #3 /var/www/user/data/www/test_write_file_new.php(88): React\EventLoop\ExtUvLoop->run() #4 {main}
error_or_not resolved with someValue:
Using React\Filesystem\ChildProcess\Adapter
Timed out after 15 seconds
#0 /var/www/user/data/www/vendor/react/event-loop/src/Timer/Timers.php(96): React\Promise\Timer\{closure}(Object(React\EventLoop\Timer\Timer)) #1 /var/www/user/data/www/vendor/react/event-loop/src/StreamSelectLoop.php(184): React\EventLoop\Timer\Timers->tick() #2 /var/www/user/data/www/test_write_file_new.php(88): React\EventLoop\StreamSelectLoop->run() #3 {main}
error_or_not resolved with someValue:
Using React\Filesystem\ChildProcess\Adapter
Timed out after 15 seconds
#0 /var/www/user/data/www/vendor/react/event-loop/src/ExtEventLoop.php(243): React\Promise\Timer\{closure}(Object(React\EventLoop\Timer\Timer)) #1 [internal function]: React\EventLoop\ExtEventLoop->React\EventLoop\{closure}(-1, 1, Object(React\EventLoop\Timer\Timer)) #2 /var/www/user/data/www/vendor/react/event-loop/src/ExtEventLoop.php(204): EventBase->loop(1) #3 /var/www/user/data/www/test_write_file_new.php(92): React\EventLoop\ExtEventLoop->run() #4 {main}
error_or_not resolved with someValue:
I'm using next versions of libraries:
- react/event-loop v1.1.0 a0ecac955c67b57c40fe4a1b88a7cca1b58c982d
- react/filesystem v0.1.2 766cdef9ba806367114f0c5ba36ea2a6eec8ccd2
Do you need any additional information?
You mentioned PHP-FPM, does this mean what you're trying to do runs in PHP-FPM?
Yes.
Hmm ok, just FYI we don't test anything in PHP-FPM, it shouldn't matter tho.
Well, I should, first of all, check the same code with PHP in CLI mode, to exclude php-fpm compatibility. I've checked it recently and can confirm that in CLI it works as expected with each adapter (ChildProcess, UV and EIO), so the issue is related to php-fpm compatibility.
Though, I'm using php-fpm with other reactphp libraries (event-loop, promises, mysql, http-client/buzz-browser) almost everyday over 6 months and can't remember similar problems, so it may depend only on this (filesystem) library.