{"id":1675,"date":"2022-08-30T15:18:30","date_gmt":"2022-08-30T15:18:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/what-is-the-best-way-to-handle-warning-mysql_connect-too-many-connections-with-kohana-3-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:30","modified_gmt":"2022-08-30T15:18:30","slug":"what-is-the-best-way-to-handle-warning-mysql_connect-too-many-connections-with-kohana-3-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/what-is-the-best-way-to-handle-warning-mysql_connect-too-many-connections-with-kohana-3-collection-of-common-programming-errors\/","title":{"rendered":"What is the best way to handle &ldquo;Warning: mysql_connect(): Too many connections&rdquo; with Kohana 3?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;ve got a web application that is used by a company for logging their employees&#8217; work.<\/p>\n<p>A lot of people are often logged in at once.<\/p>\n<p>The application runs on a shared host.<\/p>\n<p>I sometimes receive&#8230;<\/p>\n<blockquote>\n<p>Warning: mysql_connect() [function.mysql-connect]: Too many connections<\/p>\n<\/blockquote>\n<p>Which then lets further errors cascade&#8230; like errors with <code>mysql_select_db()<\/code>, <code>mysql_error()<\/code>, <code>mysql_errnon()<\/code> and finally the uncaught <code>Database_Eexception<\/code>.<\/p>\n<p>When I run my main request, I wrap it in a <code>try<\/code> and capture any exception and display a <em>not found<\/em> page. This is because usually my controllers throw exceptions if a resource is not found (though the route may be valid) e.g. <code>http:\/\/example.com\/products\/30<\/code> is a valid route, but product #30 doesn&#8217;t exist.<\/p>\n<p>What is the best way to handle the <em>too many connections<\/em>? Ideally I&#8217;d like to capture that exception separately, then display a nice page that informs the employee to try again in 5 minutes.<\/p>\n<p>The code that runs my main request in <code>application\/bootstrap.php<\/code> looks like this&#8230;<\/p>\n<pre><code>$request = Request::instance();\n\ntry {\n    $request-&gt;execute();\n} catch (Exception $e) {\n\n    if (Kohana::$environment === Kohana::DEVELOPMENT) throw $e;\n\n    \/\/ Log the error\n    Kohana::$log-&gt;add(Kohana::ERROR, Kohana::exception_text($e));\n\n    \/\/ Create a 404 response\n    $request-&gt;status = 404;\n    $request-&gt;response = Request::factory(Route::get('catch_all')-&gt;uri(array('path' =&gt; 'errors\/404')))-&gt;execute();\n}\n\n$request-&gt;send_headers();\necho $request-&gt;response;\n<\/code><\/pre>\n<p>Thanks for any help!<\/p>\n<ol>\n<li>\n<p>I just created such file to handle all the errors:<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:27:01. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve got a web application that is used by a company for logging their employees&#8217; work. A lot of people are often logged in at once. The application runs on a shared host. I sometimes receive&#8230; Warning: mysql_connect() [function.mysql-connect]: Too many connections Which then lets further errors cascade&#8230; like errors with mysql_select_db(), mysql_error(), mysql_errnon() and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1675","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1675"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1675\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}