mnabialek / laravel-sql-logger

Log SQL queries for Laravel/Lumen framework
MIT License
156 stars 24 forks source link

Too many open files #22

Closed vijay-open closed 4 years ago

vijay-open commented 4 years ago

I'm using this package in background jobs. I'm getting this error

file_put_contents(/storage/logs/sql/2020-10-21-log.sql): failed to open stream: Too many open files in /vendor/mnabialek/laravel-sql-logger/src/SqlLogger.php:179

Any help on how to solve this.

I feel this could be an error reason. We should create a singleton on the SqlLogger object


//In Package ServiceProvider.php
if ($logStatus || $slowLogStatus) {
            // create logger class
            $logger = new SqlLogger($this->app, $logStatus, $slowLogStatus, $slowLogTime, $override,
                $directory, $convertToSeconds, $separateConsoleLog);

            // listen to database queries
            $this->app['db']->listen(function (
                $query,
                $bindings = null,
                $time = null
            ) use ($logger) {
                $logger->log($query, $bindings, $time);
            });
        }

Php version: 7.3 Laravel version: 5.4 Package version: 1.1.4,

mnabialek commented 4 years ago

Thank you for reporting. I don't think making singleton would help but you should do 2 things:

  1. Please upgrade package to latest 2.* version
  2. Verify your system settings https://stackoverflow.com/a/14749074/3593996 - if your system is making a lot of disk operations, you should increase this limit to avoid similar errors