Cannot connect to database SQLSTATE[HY000] [1040] Too many connections (500 Internal Server Error)

Symfony Exception

PDOException

HTTP 500 Internal Server Error

SQLSTATE[HY000] [1040] Too many connections

Exception

PDOException

Show exception properties
PDOException {#2570
  +errorInfo: array:3 [
    0 => "HY000"
    1 => 1040
    2 => "Too many connections"
  ]
}
  1.         return null;
  2.     }
  3.     // Create connection
  4.     $conn = new \PDO("mysql:host={$servername};port={$port};dbname={$dbname};charset=utf8"$username$password);
  5.     $conn->query('SELECT 1');
  6.     return $conn;
  7. }
PDO->__construct('mysql:host=mysql;port=3306;dbname=crm;charset=utf8', 'crm', object(SensitiveParameterValue)) in /var/www/crm/variables/functions.php (line 509)
  1.         return null;
  2.     }
  3.     // Create connection
  4.     $conn = new \PDO("mysql:host={$servername};port={$port};dbname={$dbname};charset=utf8"$username$password);
  5.     $conn->query('SELECT 1');
  6.     return $conn;
  7. }
connect_to_mysql() in /var/www/crm/variables/functions.php (line 1375)
  1.  * @return MedicalCenter
  2.  * @deprecated
  3.  */
  4. function get_parent_entity($request null)
  5. {
  6.     if (!connect_to_mysql()) {
  7.         return null;
  8.     }
  9.     $tags = [env('API_ANALIZI_TOKEN')];
  10.     $cache_key 'parent-entity-info' get_domain_app_name();
get_parent_entity() in /var/www/crm/variables/functions.php (line 1844)
  1.  */
  2. function is_csd()
  3. {
  4.     $check false;
  5.     $parent_entity get_parent_entity();
  6.     if ($parent_entity && $parent_entity->parent_type == 'medical_center' && ($parent_entity->name === 'CSD' || $parent_entity->name === 'CSD ACC')) {
  7.         $check true;
  8.     }
  1.      */
  2.     public static function getSubSiteViewFullPath(string $viewPath): string
  3.     {
  4.         $medCenterPart 'default';
  5.         if (is_csd()) {
  6.             $medCenterPart 'csd';
  7.         }
  8.         $viewPathParts explode('.'$viewPath);
  9.         array_splice($viewPathParts10, [$medCenterPart]);
MedicalCenterInstance::getSubSiteViewFullPath('sub-site.master') in /var/www/crm/app/Providers/ComposerServiceProvider.php (line 27)
  1.      */
  2.     public function boot()
  3.     {
  4.         \View::composer('sub-site.*'SubSiteCompose::class);
  5.         \View::composer(
  6.             MedicalCenterInstance::getSubSiteViewFullPath('sub-site.master'),
  7.             SubSiteMasterCompose::class
  8.         );
  9.         \View::composer(['layouts.header-lab''layouts.header-center'], HeaderCompose::class);
  10.         \View::composer('layouts.layout'LayoutCompose::class);
  11.     }
  1.         if (static::isCallableWithAtSign($callback) || $defaultMethod) {
  2.             return static::callClass($container$callback$parameters$defaultMethod);
  3.         }
  4.         return static::callBoundMethod($container$callback, function () use ($container$callback$parameters) {
  5.             return $callback(...array_values(static::getMethodDependencies($container$callback$parameters)));
  6.         });
  7.     }
  8.     /**
  9.      * Call a string reference to a class using Class@method syntax.
  1.      * @param  mixed  ...$args
  2.      * @return mixed
  3.      */
  4.     public static function unwrapIfClosure($value, ...$args)
  5.     {
  6.         return $value instanceof Closure $value(...$args) : $value;
  7.     }
  8.     /**
  9.      * Get the class name of the given parameter's type, if possible.
  10.      *
  1.         if ($container->hasMethodBinding($method)) {
  2.             return $container->callMethodBinding($method$callback[0]);
  3.         }
  4.         return Util::unwrapIfClosure($default);
  5.     }
  6.     /**
  7.      * Normalize the given callback into a Class@method string.
  8.      *
  1.         if (static::isCallableWithAtSign($callback) || $defaultMethod) {
  2.             return static::callClass($container$callback$parameters$defaultMethod);
  3.         }
  4.         return static::callBoundMethod($container$callback, function () use ($container$callback$parameters) {
  5.             return $callback(...array_values(static::getMethodDependencies($container$callback$parameters)));
  6.         });
  7.     }
  8.     /**
  1.             $this->buildStack[] = $className;
  2.             $pushedToBuildStack true;
  3.         }
  4.         $result BoundMethod::call($this$callback$parameters$defaultMethod);
  5.         if ($pushedToBuildStack) {
  6.             array_pop($this->buildStack);
  7.         }
  1.     protected function bootProvider(ServiceProvider $provider)
  2.     {
  3.         $provider->callBootingCallbacks();
  4.         if (method_exists($provider'boot')) {
  5.             $this->call([$provider'boot']);
  6.         }
  7.         $provider->callBootedCallbacks();
  8.     }
  1.         // for any listeners that need to do work after this initial booting gets
  2.         // finished. This is useful when ordering the boot-up processes we run.
  3.         $this->fireAppCallbacks($this->bootingCallbacks);
  4.         array_walk($this->serviceProviders, function ($p) {
  5.             $this->bootProvider($p);
  6.         });
  7.         $this->booted true;
  8.         $this->fireAppCallbacks($this->bootedCallbacks);
Application->Illuminate\Foundation\{closure}(object(ComposerServiceProvider), 41)
  1.         // Once the application has booted we will also fire some "booted" callbacks
  2.         // for any listeners that need to do work after this initial booting gets
  3.         // finished. This is useful when ordering the boot-up processes we run.
  4.         $this->fireAppCallbacks($this->bootingCallbacks);
  5.         array_walk($this->serviceProviders, function ($p) {
  6.             $this->bootProvider($p);
  7.         });
  8.         $this->booted true;
  1.      * @param  \Illuminate\Contracts\Foundation\Application  $app
  2.      * @return void
  3.      */
  4.     public function bootstrap(Application $app)
  5.     {
  6.         $app->boot();
  7.     }
  8. }
  1.         $this->hasBeenBootstrapped true;
  2.         foreach ($bootstrappers as $bootstrapper) {
  3.             $this['events']->dispatch('bootstrapping: '.$bootstrapper, [$this]);
  4.             $this->make($bootstrapper)->bootstrap($this);
  5.             $this['events']->dispatch('bootstrapped: '.$bootstrapper, [$this]);
  6.         }
  7.     }
  1.      * @return void
  2.      */
  3.     public function bootstrap()
  4.     {
  5.         if (! $this->app->hasBeenBootstrapped()) {
  6.             $this->app->bootstrapWith($this->bootstrappers());
  7.         }
  8.     }
  9.     /**
  10.      * Get the route dispatcher callback.
  1.     {
  2.         $this->app->instance('request'$request);
  3.         Facade::clearResolvedInstance('request');
  4.         $this->bootstrap();
  5.         return (new Pipeline($this->app))
  6.                     ->send($request)
  7.                     ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
  8.                     ->then($this->dispatchToRouter());
  1.         $this->requestStartedAt Carbon::now();
  2.         try {
  3.             $request->enableHttpMethodParameterOverride();
  4.             $response $this->sendRequestThroughRouter($request);
  5.         } catch (Throwable $e) {
  6.             $this->reportException($e);
  7.             $response $this->renderException($request$e);
  8.         }
Kernel->handle(object(Request)) in /var/www/crm/public/index.php (line 54)
  1. |
  2. */
  3. $kernel $app->make(Illuminate\Contracts\Http\Kernel::class);
  4. $response $kernel->handle(
  5.     $request Illuminate\Http\Request::capture()
  6. );
  7. $response->send();

Stack Trace

PDOException
PDOException:
SQLSTATE[HY000] [1040] Too many connections

  at /var/www/crm/variables/functions.php:509
  at PDO->__construct('mysql:host=mysql;port=3306;dbname=crm;charset=utf8', 'crm', object(SensitiveParameterValue))
     (/var/www/crm/variables/functions.php:509)
  at connect_to_mysql()
     (/var/www/crm/variables/functions.php:1375)
  at get_parent_entity()
     (/var/www/crm/variables/functions.php:1844)
  at is_csd()
     (/var/www/crm/app/Services/MedicalCenter/MedicalCenterInstance.php:239)
  at App\Services\MedicalCenter\MedicalCenterInstance::getSubSiteViewFullPath('sub-site.master')
     (/var/www/crm/app/Providers/ComposerServiceProvider.php:27)
  at App\Providers\ComposerServiceProvider->boot()
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36)
  at Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Container/Util.php:41)
  at Illuminate\Container\Util::unwrapIfClosure(object(Closure))
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93)
  at Illuminate\Container\BoundMethod::callBoundMethod(object(Application), array(object(ComposerServiceProvider), 'boot'), object(Closure))
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35)
  at Illuminate\Container\BoundMethod::call(object(Application), array(object(ComposerServiceProvider), 'boot'), array(), null)
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Container/Container.php:661)
  at Illuminate\Container\Container->call(array(object(ComposerServiceProvider), 'boot'))
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:929)
  at Illuminate\Foundation\Application->bootProvider(object(ComposerServiceProvider))
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:910)
  at Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(object(ComposerServiceProvider), 41)
  at array_walk(array(object(EventServiceProvider), object(LogServiceProvider), object(RoutingServiceProvider), object(AuthServiceProvider), object(CookieServiceProvider), object(DatabaseServiceProvider), object(EncryptionServiceProvider), object(FilesystemServiceProvider), object(FormRequestServiceProvider), object(ParallelTestingServiceProvider), object(FoundationServiceProvider), object(NotificationServiceProvider), object(PaginationServiceProvider), object(SessionServiceProvider), object(ViewServiceProvider), object(ServiceProvider), object(ServiceProvider), object(DropboxServiceProvider), object(TrustedProxyServiceProvider), object(ImageServiceProvider), object(JavaScriptServiceProvider), object(UiServiceProvider), object(ExcelServiceProvider), object(LaravelJsLocalizationServiceProvider), object(ServiceProvider), object(CollisionServiceProvider), object(TermwindServiceProvider), object(ServiceProvider), object(ServiceProvider), object(ServiceProvider), object(QrCodeServiceProvider), object(PartialCacheServiceProvider), object(PermissionServiceProvider), object(LaravelServiceProvider), object(FileUploadServiceProvider), object(TurboSmsServiceProvider), object(ServiceProvider), object(AppServiceProvider), object(AuthServiceProvider), object(EventServiceProvider), object(RouteServiceProvider), object(ComposerServiceProvider), object(L3ServiceProvider), object(CacheServiceProvider), object(RedisServiceProvider), object(SocialiteServiceProvider), object(BroadcastServiceProvider), object(TranslationServiceProvider)), object(Closure))
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:909)
  at Illuminate\Foundation\Application->boot()
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17)
  at Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(object(Application))
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:242)
  at Illuminate\Foundation\Application->bootstrapWith(array('Illuminate\\Foundation\\Bootstrap\\LoadEnvironmentVariables', 'Illuminate\\Foundation\\Bootstrap\\LoadConfiguration', 'Illuminate\\Foundation\\Bootstrap\\HandleExceptions', 'Illuminate\\Foundation\\Bootstrap\\RegisterFacades', 'Illuminate\\Foundation\\Bootstrap\\RegisterProviders', 'Illuminate\\Foundation\\Bootstrap\\BootProviders'))
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176)
  at Illuminate\Foundation\Http\Kernel->bootstrap()
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:160)
  at Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(object(Request))
     (/var/www/crm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:134)
  at Illuminate\Foundation\Http\Kernel->handle(object(Request))
     (/var/www/crm/public/index.php:54)