DEV Community

Seatgo
Seatgo

Posted on

Laravel queue encounters "Failed to open stream: Too many open files"

During the execution of Laravel queues, the error "Failed to open stream: Too many open files" occurred, but the normal web service is functioning without issues. This is highly likely caused by an anomaly in the queue process.

1. Solution

We can check the current limit using:

ulimit -n
Enter fullscreen mode Exit fullscreen mode

If the current limit is too low, it can be changed to 65536.

ulimit -n 65536
Enter fullscreen mode Exit fullscreen mode

However, for PHP, simply modifying the LimitNOFILE limit usually does not solve the problem; we need to check other configurations.
The Laravel team has deprecated the --daemon mode because memory and resource leaks are unavoidable.
We just need to modify the supervisor configuration for our queue:
ini

2. How to troubleshoot?

We can check what is occupying the file descriptors. The specific method is as follows (shows all occupations, with the count first and the PID second):

lsof | awk '{print $2}' | sort | uniq -c | sort -nr | head -10
Enter fullscreen mode Exit fullscreen mode

Once we see the usage count, we can identify which software is occupying them, making it easier to find the cause and solve the problem.

ps -p 1331 -o pid,ppid,cmd,user,%cpu,%mem,lstart
Enter fullscreen mode Exit fullscreen mode

Or simply:

ps -p 1331 -f
Enter fullscreen mode Exit fullscreen mode

Top comments (0)