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
ab59a795
Commit
ab59a795
authored
Jan 21, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more reliable way of saving debug index file
fixes #1884
parent
f112cc63
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
9 deletions
+35
-9
LogTarget.php
extensions/debug/LogTarget.php
+35
-9
No files found.
extensions/debug/LogTarget.php
View file @
ab59a795
...
...
@@ -8,6 +8,7 @@
namespace
yii\debug
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\log\Target
;
/**
...
...
@@ -45,15 +46,10 @@ class LogTarget extends Target
if
(
!
is_dir
(
$path
))
{
mkdir
(
$path
);
}
$indexFile
=
"
$path
/index.data"
;
if
(
!
is_file
(
$indexFile
))
{
$manifest
=
[];
}
else
{
$manifest
=
unserialize
(
file_get_contents
(
$indexFile
));
}
$request
=
Yii
::
$app
->
getRequest
();
$response
=
Yii
::
$app
->
getResponse
();
$
manifest
[
$this
->
tag
]
=
$
summary
=
[
$summary
=
[
'tag'
=>
$this
->
tag
,
'url'
=>
$request
->
getAbsoluteUrl
(),
'ajax'
=>
$request
->
getIsAjax
(),
...
...
@@ -63,7 +59,6 @@ class LogTarget extends Target
'statusCode'
=>
$response
->
statusCode
,
'sqlCount'
=>
$this
->
getSqlTotalCount
(),
];
$this
->
gc
(
$manifest
);
$dataFile
=
"
$path
/
{
$this
->
tag
}
.data"
;
$data
=
[];
...
...
@@ -72,7 +67,38 @@ class LogTarget extends Target
}
$data
[
'summary'
]
=
$summary
;
file_put_contents
(
$dataFile
,
serialize
(
$data
));
file_put_contents
(
$indexFile
,
serialize
(
$manifest
));
$indexFile
=
"
$path
/index.data"
;
$this
->
updateIndexFile
(
$indexFile
,
$summary
);
}
private
function
updateIndexFile
(
$indexFile
,
$summary
)
{
touch
(
$indexFile
);
if
((
$fp
=
@
fopen
(
$indexFile
,
'r+'
))
===
false
)
{
throw
new
InvalidConfigException
(
"Unable to open debug data index file:
$indexFile
"
);
}
@
flock
(
$fp
,
LOCK_EX
);
$manifest
=
''
;
while
((
$buffer
=
fgets
(
$fp
))
!==
false
)
{
$manifest
.=
$buffer
;
}
if
(
!
feof
(
$fp
)
||
empty
(
$manifest
))
{
// error while reading index data, ignore and create new
$manifest
=
[];
}
else
{
$manifest
=
unserialize
(
$manifest
);
}
$manifest
[
$this
->
tag
]
=
$summary
;
$this
->
gc
(
$manifest
);
ftruncate
(
$fp
,
0
);
rewind
(
$fp
);
fwrite
(
$fp
,
serialize
(
$manifest
));
@
flock
(
$fp
,
LOCK_UN
);
@
fclose
(
$fp
);
}
/**
...
...
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