Open petsoukos opened 4 years ago
The eio error is known #43...
That child process takes long to read large files is unfortunate but it's how it is. You need to tell a child process what to do, the child process reads the file, squeezes the data through a socket and the main process needs to read the socket.
Using a buffer and strlen
is inefficient and can lead to wrong results, use stat
instead. Even eio shows here a wrong result, it reads 71MB but the file is 98MB (ls -l
). And child process fetches over 200MB....
Yes, this is unfortunate.
I put this aside for now and created what I required with another solution (which isn't a reactor pattern)
But, I would still like to give this a shot and do it with ReactPHP.
The changing numbers of filesize is related to how variables work. I've changed your one variable $buffer
to an array of integers (representing the bytes read) - so for each file there's an element in the array. This change made the filesize correct for each file. Previously due to the sharing variable (PHP is not lexical scoped) the filesize was non-deterministic and incorrect.
Description
Trying to read 10 files from disk usually ends up skipping some of them randomly with error
Takes for ever to load with the ChildProcess adapter.
strlen()
also shows different bytes each time (might be different issue)OS/PHP versions
Sample script
https://gist.github.com/petsoukos/2cc5f7cc3181efbaab12d43fbe325644
Create some random files with sizes over 3MB up to 150MB and store em in a "downloads" folder or adjust the script to point to your files.
Sample output