【发布时间】:2010-11-15 23:50:35
【问题描述】:
我有一个 Web 应用程序,公司使用它来记录员工的工作。
很多人经常同时登录。
应用程序在共享主机上运行。
我有时会收到...
警告:mysql_connect() [function.mysql-connect]:连接太多
这会让更多的错误级联...比如mysql_select_db()、mysql_error()、mysql_errnon() 的错误,最后是未捕获的Database_Eexception。
当我运行我的主请求时,我将它包装在一个 try 中并捕获任何异常并显示一个 not found 页面。这是因为如果找不到资源(尽管路由可能有效),我的控制器通常会抛出异常,例如http://example.com/products/30 是有效路线,但产品 #30 不存在。
处理太多连接的最佳方法是什么?理想情况下,我想单独捕获该异常,然后显示一个漂亮的页面,通知员工在 5 分钟后重试。
在application/bootstrap.php 中运行我的主要请求的代码如下所示...
$request = Request::instance();
try {
$request->execute();
} catch (Exception $e) {
if (Kohana::$environment === Kohana::DEVELOPMENT) throw $e;
// Log the error
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));
// Create a 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;
感谢您的帮助!
【问题讨论】:
标签: php exception-handling kohana kohana-3