php - What is the best way to handle "Warning: mysql_connect(): Too many connections" with Kohana 3? -
i've got web application used company logging employees' work.
a lot of people logged in @ once.
the application runs on shared host.
i receive...
warning: mysql_connect() [function.mysql-connect]: many connections
which lets further errors cascade... errors mysql_select_db()
, mysql_error()
, mysql_errnon()
, uncaught database_eexception
.
when run main request, wrap in try
, capture exception , display not found page. because controllers throw exceptions if resource not found (though route may valid) e.g. http://example.com/products/30
valid route, product #30 doesn't exist.
what best way handle too many connections? ideally i'd capture exception separately, display nice page informs employee try again in 5 minutes.
the code runs main request in application/bootstrap.php
looks this...
$request = request::instance(); try { $request->execute(); } catch (exception $e) { if (kohana::$environment === kohana::development) throw $e; // log error kohana::$log->add(kohana::error, kohana::exception_text($e)); // create 404 response $request->status = 404; $request->response = request::factory(route::get('catch_all')->uri(array('path' => 'errors/404')))->execute(); } $request->send_headers(); echo $request->response;
thanks help!
i created such file handle errors:
<?php class kohana extends kohana_core { /** * redirect custom exception_handler */ public static function exception_handler(exception $e) { if (kohana::development === kohana::$environment) { // pass kohana if we're in development environment parent::exception_handler($e); } else { kohana::$log->add(kohana::error, kohana::exception_text($e)); // default route $route = route::url('default', array('controller' => 'error', 'action' => '404')); // error sub-request. echo request::factory($route) ->execute() ->send_headers() ->response; } } }
for sketch, give ideas.
ps: bootstrap not modified
Comments
Post a Comment