Skip to content

fget truncate alternative? #104

@valzargaming

Description

@valzargaming

I'm hoping to port some of my existing code over to ReactPHP Filesystem to make reading lines from a file and truncating it afterwards asynchronous so that my main loop can still be working on other time sensitive tasks, like listening for events fired over a socket. The current documentation doesn't really give me a good idea of how to do this, and only some of the snippets seem to be relevant to my usage. What would be filesystem's equivalent to this?

if ($file = fopen($file_path, "r+")) {
    while (($fp = fgets($file, 4096)) !== false) {
        $fp = str_replace(PHP_EOL, "", $fp);
        //Do stuff with the line
    }
    ftruncate($file, 0);
    fclose($file);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions