Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
RRZE Webteam
RRZE Cache
Commits
a4f97b68
Commit
a4f97b68
authored
Nov 06, 2020
by
Rolf Forst
Browse files
Update cache output
parent
2ed722da
Changes
1
Hide whitespace changes
Inline
Side-by-side
advanced-cache.php
View file @
a4f97b68
...
...
@@ -3,10 +3,6 @@ if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'GET') {
return
false
;
}
if
(
!
empty
(
$_GET
)
&&
!
isset
(
$_GET
[
'utm_source'
],
$_GET
[
'utm_medium'
],
$_GET
[
'utm_campaign'
]))
{
return
false
;
}
if
(
!
empty
(
$_COOKIE
))
{
foreach
(
$_COOKIE
as
$k
=>
$v
)
{
if
(
preg_match
(
'/^(wp-postpass|wordpress_logged_in|comment_author)_/'
,
$k
))
{
...
...
@@ -16,45 +12,34 @@ if (!empty($_COOKIE)) {
}
$timeout_file
=
WP_CONTENT_DIR
.
'/advanced-cache/timeout'
;
$expires_seconds
=
MINUTE_IN_SECONDS
;
$expires_seconds
=
10
*
MINUTE_IN_SECONDS
;
if
(
is_readable
(
$timeout_file
)
&&
(
$buffer
=
file_get_contents
(
$timeout_file
)
)
!==
false
)
{
$expires_seconds
=
(
int
)
$buffer
*
MINUTE_IN_SECONDS
;
if
(
is_readable
(
$timeout_file
)
&&
filesize
(
$timeout_file
)
>
0
)
{
$expires_seconds
=
abs
(
int
val
(
file_get_contents
(
$timeout_file
)))
*
MINUTE_IN_SECONDS
;
}
$expires_seconds
=
$expires_seconds
>=
MINUTE_IN_SECONDS
?
$expires_seconds
:
MINUTE_IN_SECONDS
;
$expires_seconds
=
$expires_seconds
>=
(
1
*
MINUTE_IN_SECONDS
)
?
$expires_seconds
:
(
10
*
MINUTE_IN_SECONDS
)
;
$path
=
sprintf
(
'%s%s%s%s'
,
WP_CONTENT_DIR
.
'/advanced-cache'
,
DIRECTORY_SEPARATOR
,
parse_url
(
'https://'
.
strtolower
(
$_SERVER
[
'HTTP_HOST'
]),
PHP_URL_HOST
),
parse_url
(
$_SERVER
[
'REQUEST_URI'
],
PHP_URL_PATH
)
);
$path
=
WP_CONTENT_DIR
.
'/advanced-cache'
.
DIRECTORY_SEPARATOR
.
parse_url
(
'https://'
.
strtolower
(
$_SERVER
[
'HTTP_HOST'
]),
PHP_URL_HOST
)
.
parse_url
(
$_SERVER
[
'REQUEST_URI'
],
PHP_URL_PATH
);
$path
=
rtrim
(
$path
,
'/\\'
)
.
'/'
;
$path_html
=
$path
.
'index.html'
;
if
(
is_readable
(
$path_html
)
&&
(
$buffer
=
file_get_contents
(
$path_html
))
!==
false
&&
((
filemtime
(
$path_html
)
+
$expires_seconds
)
>
time
()))
{
if
(
function_exists
(
'apache_request_headers'
))
{
$headers
=
apache_request_headers
();
$http_if_modified_since
=
isset
(
$headers
[
'If-Modified-Since'
])
?
$headers
[
'If-Modified-Since'
]
:
''
;
$http_accept
=
isset
(
$headers
[
'Accept'
])
?
$headers
[
'Accept'
]
:
''
;
$http_accept_encoding
=
isset
(
$headers
[
'Accept-Encoding'
])
?
$headers
[
'Accept-Encoding'
]
:
''
;
}
else
{
$http_if_modified_since
=
isset
(
$_SERVER
[
'HTTP_IF_MODIFIED_SINCE'
])
?
$_SERVER
[
'HTTP_IF_MODIFIED_SINCE'
]
:
''
;
$http_accept
=
isset
(
$_SERVER
[
'HTTP_ACCEPT'
])
?
$_SERVER
[
'HTTP_ACCEPT'
]
:
''
;
$http_accept_encoding
=
isset
(
$_SERVER
[
'HTTP_ACCEPT_ENCODING'
])
?
$_SERVER
[
'HTTP_ACCEPT_ENCODING'
]
:
''
;
}
$cache_file
=
$path
.
'index.html'
;
if
(
$http_if_modified_since
&&
strtotime
(
$http_if_modified_since
)
==
filemtime
(
$path_html
))
{
header
(
$_SERVER
[
'SERVER_PROTOCOL'
]
.
' 304 Not Modified'
,
true
,
304
);
// Check if the cache file exists and is readable.
if
(
is_readable
(
$cache_file
)
&&
(
$content
=
file_get_contents
(
$cache_file
))
!==
false
&&
(
filesize
(
$cache_file
)
>
0
))
{
// Check if the cache file is not stale.
if
((
$filemtime
=
filemtime
(
$cache_file
)
+
$expires_seconds
)
>
time
())
{
// Not stale: Output the content of the cache file.
header
(
'Last-Modified: '
.
date
(
'r'
,
$filemtime
),
true
);
header
(
'Cache-Control: max-age='
.
$expires_seconds
.
', must-revalidate'
,
true
);
echo
$content
;
exit
;
}
else
{
// Stale: Remove the cache file.
unlink
(
$cache_file
);
}
echo
$buffer
;
exit
;
}
Write
Preview
Supports
Markdown
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