Zend Framework, IIS and 500 errors
Join the DZone community and get the full member experience.
Join For Freeone of the dangers of frameworks in general is that you forget that they do lots of handy things for you.
consider zend framework's default error controller:
public function erroraction() { $errors = $this->_getparam('error_handler'); switch ($errors->type) { case zend_controller_plugin_errorhandler::exception_no_route: case zend_controller_plugin_errorhandler::exception_no_controller: case zend_controller_plugin_errorhandler::exception_no_action: // 404 error -- controller or action not found $this->getresponse()->sethttpresponsecode(404); $this->view->message = 'page not found'; break; default: // application error $this->getresponse()->sethttpresponsecode(500); $this->view->message = 'application error'; break; } // log exception, if logger available if ($log = $this->getlog()) { $log->crit($this->view->message, $errors->exception); } // conditionally display exceptions if ($this->getinvokearg('displayexceptions') == true) { $this->view->exception = $errors->exception; } $this->view->request = $errors->request; }
the error handler in zf will catch any exceptions and route them to the error action in the error controller. this then sets the correct http response code, logs the error and optionally displays it if a config setting is set.
obviously on our production boxes, we don't display the exceptions, but we do on our local development machines.
iis has the concept of custom error pages that it displays when the app returns a 4xx or 5xx status code:
there is also some settings for this page:
by default this is set so that if you access the site using the localhost domain, then you'll get the zf error page and if you access the site remotely then you'll get the iis custom page and won't see the error.
if, like me, you are developing with your iis in a vm and using the host os's browser and developer tools, then you need to change the setting to "detailed":
now you can see your exceptions and it doesn't look like php has crashed :)
Published at DZone with permission of Rob Allen, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
RBAC With API Gateway and Open Policy Agent (OPA)
-
A Data-Driven Approach to Application Modernization
-
What Is JHipster?
-
JavaFX Goes Mobile
Comments