amphp / file

An abstraction layer and non-blocking file access solution that keeps your application responsive.
MIT License
97 stars 25 forks source link

The write function blocks the completion of Eventloop::Run() #82

Open PhantomArt opened 7 months ago

PhantomArt commented 7 months ago

I'm running the following code:

write('file.txt', 'text');
EventLoop::run(); // it never ends

Writing the file works as expected, the script hangs on the EventLoop::run() call. I have a Windows operating system. I didn't install any additional extensions for event loop.

I only see this problem when using the write function. I don't see this problem when I use Amp\Http, including when I run asynchronous operations using the async function. The problem also disappears if I replace write with file_put_contents.

kelunik commented 7 months ago

Do you use the latest versions?

PhantomArt commented 7 months ago

I have PHP 8.2.5. I created a new folder and ran:

composer require amphp/file
composer require amphp/http-client

After this I create a new file with the following content:

<?php

require __DIR__ . '/vendor/autoload.php';

Amp\File\write('file.txt', 'text');
Revolt\EventLoop::run(); // it never ends

The contents of composer.json look like this:

{
    "require": {
        "amphp/file": "^3.0",
        "amphp/http-client": "^5.0"
    }
}
PhantomArt commented 7 months ago

I ran the same test on PHP 8.2.13 on Linux, there is no problem there.