Help for integrating the Laravel package
Forum rules: Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#8193 by Harpal Singh
14 Jun 2019, 05:50
Hi,
I am getting an exception randomly like ErrorException (E_ERROR)
An exception occurred in driver: SQLSTATE[HY000] [1040] Too many connections
in my 'frontpanel_nav.blade.php' file.

This happens randomly on any page of the site. Sometimes the same page runs smoothly as usual but sometimes this exception appears on the same page.

Thanks
Harpal Singh
#8218 by Harpal Singh
17 Jun 2019, 11:04
I havn't extended any class but using calling some header functions in my files like :
Code: Select all/** To Get language and Currency **/
function getLocaleCurrency()
{
    $arr = [];
    $context = app( '\Aimeos\Shop\Base\Context')->get();
    $locale = $context->getLocale();
    $arr['language'] = $locale->getLanguageId();
    $arr['currency'] = $locale->getCurrencyId();
    $arr['site'] = $locale->getSite();
    return $arr;
}

function getCategoryByProductId($id) {
    $context = app('\Aimeos\Shop\Base\Context')->get();
    /** @var \Aimeos\MShop\Catalog\Manager\Standard $manager */
    $manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $context );
    $search = $manager->createSearch( true );
    $expr = array(
        $search->compare('==', 'catalog.lists.refid', $id),
        $search->compare('==', 'catalog.lists.domain', 'product'),
    );
    $search->setConditions($search->combine('&&', $expr));
    $categoryItems = $manager->searchItems($search);
     return $categoryItems;
}
etc.

and I think there is problem in these functions.
If you have overwritten any classes, please make sure you have as release() for each acquire(), even on exceptions.

How can I release connection? I mean What is syntax for it.

Code: Select allAimeos\MW\DB\Exception thrown with message "An exception occurred in driver: SQLSTATE[HY000] [1040] Too many connections"

Stacktrace:
#69 Aimeos\MW\DB\Exception in /vendor/aimeos/aimeos-core/lib/mwlib/src/MW/DB/Manager/DBAL.php:114
#68 Aimeos\MW\DB\Manager\DBAL:acquire in /vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Common/Manager/Base.php:83
#67 Aimeos\MShop\Common\Manager\Base:createSearch in /vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Catalog/Manager/Standard.php:269
#66 Aimeos\MShop\Catalog\Manager\Standard:createSearch in /vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Common/Manager/Base.php:302
#65 Aimeos\MShop\Common\Manager\Base:createSearchBase in /vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Catalog/Manager/Standard.php:266
#64 Aimeos\MShop\Catalog\Manager\Standard:createSearch in /vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Common/Manager/Decorator/Base.php:88
#63 Aimeos\MShop\Common\Manager\Decorator\Base:createSearch in /app/Helper/helper.php:2120
#62 getCategoryByProductId in /ext/azx/client/html/templates/catalog/detail/body-standard.php:207
#61 include in /vendor/aimeos/aimeos-core/lib/mwlib/src/MW/View/Standard.php:251
#60 Aimeos\MW\View\Standard:includeFile in /vendor/aimeos/aimeos-core/lib/mwlib/src/MW/View/Standard.php:233
#59 Aimeos\MW\View\Standard:render in /ext/ai-client-html/client/html/src/Client/Html/Catalog/Detail/Standard.php:192
#58 Aimeos\Client\Html\Catalog\Detail\Standard:getBody in /vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Base/Page.php:91
#57 Aimeos\Shop\Base\Page:getSections in /vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Controller/CatalogController.php:46
#56 Aimeos\Shop\Controller\CatalogController:detailAction in /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#55 call_user_func_array in /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#54 Illuminate\Routing\Controller:callAction in /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
#53 Illuminate\Routing\ControllerDispatcher:dispatch in /vendor/laravel/framework/src/Illuminate/Routing/Route.php:212
#52 Illuminate\Routing\Route:runController in /vendor/laravel/framework/src/Illuminate/Routing/Route.php:169
#51 Illuminate\Routing\Route:run in /vendor/laravel/framework/src/Illuminate/Routing/Router.php:665
#50 Illuminate\Routing\Router:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#49 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
#48 Illuminate\Routing\Middleware\SubstituteBindings:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#47 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#46 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:68
#45 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#44 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#43 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#42 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#41 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#40 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:63
#39 Illuminate\Session\Middleware\StartSession:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#38 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#37 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#36 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#35 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#34 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:66
#33 Illuminate\Cookie\Middleware\EncryptCookies:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#32 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#31 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#30 Illuminate\Pipeline\Pipeline:then in /vendor/laravel/framework/src/Illuminate/Routing/Router.php:667
#29 Illuminate\Routing\Router:runRouteWithinStack in /vendor/laravel/framework/src/Illuminate/Routing/Router.php:642
#28 Illuminate\Routing\Router:runRoute in /vendor/laravel/framework/src/Illuminate/Routing/Router.php:608
#27 Illuminate\Routing\Router:dispatchToRoute in /vendor/laravel/framework/src/Illuminate/Routing/Router.php:597
#26 Illuminate\Routing\Router:dispatch in /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
#25 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#24 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/spatie/laravel-cookie-consent/src/CookieConsentMiddleware.php:12
#23 Spatie\CookieConsent\CookieConsentMiddleware:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#22 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#21 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /app/Http/Middleware/SetLocale.php:99
#20 App\Http\Middleware\SetLocale:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#19 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#18 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/fideloper/proxy/src/TrustProxies.php:57
#17 Fideloper\Proxy\TrustProxies:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
#5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#2 Illuminate\Pipeline\Pipeline:then in /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in /public/index.php:66


Thanks
Harpal Singh
#8225 by aimeos
18 Jun 2019, 07:34
Is this a dev or production environment?

The Aimeos methods are usually save and use acquire() and release() symetrically. They also case about exceptions. You can check if you add a debug statement to the acquire() and release() methods of \Aimeos\MW\DB\Manager\DBAL (https://github.com/aimeos/aimeos-core/blob/master/lib/mwlib/src/MW/DB/Manager/DBAL.php) and compare acquire/release pairs.