How to do asynchronous file operations?

bosun

I am building a websocket service based on workermanand will like to fetch the content of a bunch of files. Doind this one after the other will take a lot of time, so I am looking for a way such that I can fetch these 10 files asynchrnously withou waiting for each to finish and then wait for all of them in the end.

I've been looking around the documentation but didn't see anything around concerning this.
Also, what is the impact of using file_get_contents, which is a blocking function, inside workerman?

Thank you.

509 2 0
2个回答

chaz6chez

You could give the aio extension a shot, fire up some aio get requests in one process, and then block and wait for results

  • chaz6chez 2023-08-22

    This method will hold up the current process, but it can also get the job done, unless you want it to run without blocking the current process.

nitron

if u fetch files via http ,u can use this
https://www.workerman.net/doc/workerman/components/workerman-http-client.html
file_get_contents will block current thread

  • bosun 2023-08-22

    The files are residing locally on the server and not on another server, so, using an http client is not beneficial for this task.

年代过于久远,无法发表回答
×
🔝