Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
f52bc485
Commit
f52bc485
authored
Apr 13, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use error_log to log fatal errors.
parent
9183e837
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
83 deletions
+54
-83
Application.php
framework/base/Application.php
+54
-83
No files found.
framework/base/Application.php
View file @
f52bc485
...
...
@@ -13,36 +13,6 @@ use yii\helpers\FileHelper;
/**
* Application is the base class for all application classes.
*
* An application serves as the global context that the user request
* is being processed. It manages a set of application components that
* provide specific functionalities to the whole application.
*
* The core application components provided by Application are the following:
* <ul>
* <li>{@link getErrorHandler errorHandler}: handles PHP errors and
* uncaught exceptions. This application component is dynamically loaded when needed.</li>
* <li>{@link getSecurityManager securityManager}: provides security-related
* services, such as hashing, encryption. This application component is dynamically
* loaded when needed.</li>
* <li>{@link getStatePersister statePersister}: provides global state
* persistence method. This application component is dynamically loaded when needed.</li>
* <li>{@link getCache cache}: provides caching feature. This application component is
* disabled by default.</li>
* </ul>
*
* Application will undergo the following life cycles when processing a user request:
* <ol>
* <li>load application configuration;</li>
* <li>set up class autoloader and error handling;</li>
* <li>load static application components;</li>
* <li>{@link beforeRequest}: preprocess the user request; `beforeRequest` event raised.</li>
* <li>{@link processRequest}: process the user request;</li>
* <li>{@link afterRequest}: postprocess the user request; `afterRequest` event raised.</li>
* </ol>
*
* Starting from lifecycle 3, if a PHP error or an uncaught exception occurs,
* the application will switch to its error handling logic and jump to step 6 afterwards.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
...
...
@@ -157,30 +127,6 @@ class Application extends Module
}
/**
* Handles fatal PHP errors
*/
public
function
handleFatalError
()
{
if
(
YII_ENABLE_ERROR_HANDLER
)
{
$error
=
error_get_last
();
if
(
ErrorException
::
isFatalError
(
$error
))
{
unset
(
$this
->
_memoryReserve
);
$exception
=
new
ErrorException
(
$error
[
'message'
],
$error
[
'type'
],
$error
[
'type'
],
$error
[
'file'
],
$error
[
'line'
]);
$this
->
logException
(
$exception
);
if
((
$handler
=
$this
->
getErrorHandler
())
!==
null
)
{
@
$handler
->
handle
(
$exception
);
}
else
{
$this
->
renderException
(
$exception
);
}
exit
(
1
);
}
}
}
/**
* Runs the application.
* This is the main entrance of an application.
* @return integer the exit status (0 means normal, non-zero values mean abnormal)
...
...
@@ -384,6 +330,45 @@ class Application extends Module
}
/**
* Handles uncaught PHP exceptions.
*
* This method is implemented as a PHP exception handler. It requires
* that constant YII_ENABLE_ERROR_HANDLER be defined true.
*
* @param \Exception $exception exception that is not caught
*/
public
function
handleException
(
$exception
)
{
// disable error capturing to avoid recursive errors while handling exceptions
restore_error_handler
();
restore_exception_handler
();
try
{
$this
->
logException
(
$exception
);
if
((
$handler
=
$this
->
getErrorHandler
())
!==
null
)
{
$handler
->
handle
(
$exception
);
}
else
{
$this
->
renderException
(
$exception
);
}
$this
->
end
(
1
);
}
catch
(
\Exception
$e
)
{
// exception could be thrown in end() or ErrorHandler::handle()
$msg
=
(
string
)
$e
;
$msg
.=
"
\n
Previous exception:
\n
"
;
$msg
.=
(
string
)
$exception
;
if
(
YII_DEBUG
)
{
echo
$msg
;
}
$msg
.=
"
\n\$
_SERVER = "
.
var_export
(
$_SERVER
,
true
);
error_log
(
$msg
);
exit
(
1
);
}
}
/**
* Handles PHP execution errors such as warnings, notices.
*
* This method is used as a PHP error handler. It will simply raise an `ErrorException`.
...
...
@@ -414,41 +399,27 @@ class Application extends Module
}
/**
* Handles uncaught PHP exceptions.
*
* This method is implemented as a PHP exception handler. It requires
* that constant YII_ENABLE_ERROR_HANDLER be defined true.
*
* @param \Exception $exception exception that is not caught
* Handles fatal PHP errors
*/
public
function
handle
Exception
(
$exception
)
public
function
handle
FatalError
(
)
{
// disable error capturing to avoid recursive errors while handling exceptions
restore_error_handler
();
restore_exception_handler
();
try
{
$this
->
logException
(
$exception
);
if
(
YII_ENABLE_ERROR_HANDLER
)
{
$error
=
error_get_last
();
if
(
(
$handler
=
$this
->
getErrorHandler
())
!==
null
)
{
$handler
->
handle
(
$exception
);
}
else
{
$this
->
renderException
(
$exception
);
}
if
(
ErrorException
::
isFatalError
(
$error
)
)
{
unset
(
$this
->
_memoryReserve
);
$exception
=
new
ErrorException
(
$error
[
'message'
],
$error
[
'type'
],
$error
[
'type'
],
$error
[
'file'
],
$error
[
'line'
]);
// use error_log because it's too late to use Yii log
error_log
(
$exception
);
$this
->
end
(
1
);
if
((
$handler
=
$this
->
getErrorHandler
())
!==
null
)
{
@
$handler
->
handle
(
$exception
);
}
else
{
$this
->
renderException
(
$exception
);
}
}
catch
(
\Exception
$e
)
{
// exception could be thrown in end() or ErrorHandler::handle()
$msg
=
(
string
)
$e
;
$msg
.=
"
\n
Previous exception:
\n
"
;
$msg
.=
(
string
)
$exception
;
if
(
YII_DEBUG
)
{
echo
$msg
;
exit
(
1
);
}
$msg
.=
"
\n\$
_SERVER = "
.
var_export
(
$_SERVER
,
true
);
error_log
(
$msg
);
exit
(
1
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment