Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Redis Page Cache
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
Redis Page Cache
Commits
658fb37c
Commit
658fb37c
authored
11 years ago
by
Rueben Ramirez
Browse files
Options
Downloads
Patches
Plain Diff
adding in some debug statements
parent
31efdc47
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
index-wp-redis.php
+39
-22
39 additions, 22 deletions
index-wp-redis.php
with
39 additions
and
22 deletions
index-wp-redis.php
+
39
−
22
View file @
658fb37c
...
@@ -35,15 +35,15 @@ function getCleanUrl($secret) {
...
@@ -35,15 +35,15 @@ function getCleanUrl($secret) {
$url
=
"http://${_SERVER['HTTP_HOST']}${_SERVER['REQUEST_URI']}"
;
$url
=
"http://${_SERVER['HTTP_HOST']}${_SERVER['REQUEST_URI']}"
;
$current_url
=
str_replace
(
$replaceKeys
,
''
,
$url
);
$current_url
=
str_replace
(
$replaceKeys
,
''
,
$url
);
return
$current_url
;
return
$current_url
;
}
}
$debug
=
true
;
$debug
=
true
;
$cache
=
false
;
$cache
=
true
;
$websiteIp
=
'127.0.0.1'
;
$websiteIp
=
'127.0.0.1'
;
$reddis_server
=
'127.0.0.1'
;
$reddis_server
=
'127.0.0.1'
;
$secret_string
=
'changeme'
;
$secret_string
=
'changeme'
;
$current_url
=
getCleanUrl
(
$secret_string
);
$redis_key
=
md5
(
$current_url
);
handleCDNRemoteAddressing
();
handleCDNRemoteAddressing
();
...
@@ -51,24 +51,31 @@ if(!defined('WP_USE_THEMES')) {
...
@@ -51,24 +51,31 @@ if(!defined('WP_USE_THEMES')) {
define
(
'WP_USE_THEMES'
,
true
);
define
(
'WP_USE_THEMES'
,
true
);
}
}
$current_url
=
getCleanUrl
(
$secret_string
);
$redis_key
=
md5
(
$current_url
);
try
{
try
{
// check if PECL Extension is available
// check if PECL Extension is available
if
(
class_exists
(
'Redis'
))
{
if
(
class_exists
(
'Redis'
))
{
if
(
$debug
)
{
echo
"<!-- Redis PECL module found -->
\n
"
;
}
$redis
=
new
Redis
();
$redis
=
new
Redis
();
// Sockets can be used as well. Documentation @ https://github.com/nicolasff/phpredis/#connection
// Sockets can be used as well. Documentation @ https://github.com/nicolasff/phpredis/#connection
$redis
->
connect
(
$reddis_server
);
$redis
->
connect
(
$reddis_server
);
}
else
{
// Fallback to predis5.2.php
}
else
{
// Fallback to predis5.2.php
if
(
$debug
)
{
echo
"<!-- using predis as a backup -->
\n
"
;
}
include_once
(
"wp-content/plugins/wp-redis-cache/predis5.2.php"
);
//we need this to use Redis inside of PHP
include_once
(
"wp-content/plugins/wp-redis-cache/predis5.2.php"
);
//we need this to use Redis inside of PHP
$redis
=
new
Predis_Client
();
$redis
=
new
Predis_Client
();
}
}
//Either manual refresh cache by adding ?refresh=secret_string after the URL or somebody posting a comment
//Either manual refresh cache by adding ?refresh=secret_string after the URL or somebody posting a comment
if
(
refreshHasSecret
(
$secret_string
)
||
requestHasSecret
(
$secret_string
)
||
isRemotePageLoad
(
$current_url
,
$websiteIp
))
{
if
(
refreshHasSecret
(
$secret_string
)
||
requestHasSecret
(
$secret_string
)
||
isRemotePageLoad
(
$current_url
,
$websiteIp
))
{
if
(
$debug
)
{
echo
"<!-- manual refresh was required -->
\n
"
;
}
$redis
->
del
(
$redis_key
);
$redis
->
del
(
$redis_key
);
require
(
'./wp-blog-header.php'
);
require
(
'./wp-blog-header.php'
);
...
@@ -76,17 +83,23 @@ try {
...
@@ -76,17 +83,23 @@ try {
$seconds_cache_redis
=
get_option
(
'wp-redis-cache-seconds'
,
43200
);
$seconds_cache_redis
=
get_option
(
'wp-redis-cache-seconds'
,
43200
);
// This page is cached, lets display it
// This page is cached, lets display it
}
else
if
(
$redis
->
exists
(
$redis_key
))
{
}
else
if
(
$redis
->
exists
(
$redis_key
))
{
if
(
$debug
)
{
echo
"<!-- serving page from cache: key:
$redis_key
-->
\n
"
;
}
$cache
=
true
;
$cache
=
true
;
$html_of_page
=
$redis
->
get
(
$redis_key
);
$html_of_page
=
$redis
->
get
(
$redis_key
);
echo
$html_of_page
;
echo
$html_of_page
;
// If the cache does not exist lets display the user the normal page without cache, and then fetch a new cache page
// If the cache does not exist lets display the user the normal page without cache, and then fetch a new cache page
}
else
if
(
$_SERVER
[
'REMOTE_ADDR'
]
!=
$ip_of_your_website
&&
strstr
(
$current_url
,
'preview=true'
)
==
false
)
{
}
else
if
(
$_SERVER
[
'REMOTE_ADDR'
]
!=
$websiteIp
&&
strstr
(
$current_url
,
'preview=true'
)
==
false
)
{
if
(
$debug
)
{
echo
"<!-- displaying page without cache -->
\n
"
;
}
$isPOST
=
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
)
?
1
:
0
;
$isPOST
=
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
)
?
1
:
0
;
$loggedIn
=
preg_match
(
"/wordpress_logged_in/"
,
var_export
(
$_COOKIE
,
true
));
$loggedIn
=
preg_match
(
"/wordpress_logged_in/"
,
var_export
(
$_COOKIE
,
true
));
if
(
$isP
ost
==
0
&&
$loggedIn
==
0
)
{
if
(
!
$isP
OST
&&
!
$loggedIn
)
{
ob_start
();
ob_start
();
require
(
'./wp-blog-header.php'
);
require
(
'./wp-blog-header.php'
);
$html_of_page
=
ob_get_contents
();
$html_of_page
=
ob_get_contents
();
...
@@ -111,25 +124,29 @@ try {
...
@@ -111,25 +124,29 @@ try {
require
(
'./wp-blog-header.php'
);
require
(
'./wp-blog-header.php'
);
}
}
}
else
if
(
$_SERVER
[
'REMOTE_ADDR'
]
!=
$
ip_of_your_
website
&&
strstr
(
$current_url
,
'preview=true'
)
==
true
)
{
}
else
if
(
$_SERVER
[
'REMOTE_ADDR'
]
!=
$website
Ip
&&
strstr
(
$current_url
,
'preview=true'
)
==
true
)
{
require
(
'./wp-blog-header.php'
);
require
(
'./wp-blog-header.php'
);
}
}
// else { // This is what your server should get if no cache exists //deprecated, as the ob_start() is cleaner
// else { // This is what your server should get if no cache exists //deprecated, as the ob_start() is cleaner
// require('./wp-blog-header.php');
// require('./wp-blog-header.php');
// }
// }
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
require
(
'./wp-blog-header.php'
);
//require('./wp-blog-header.php');
echo
"something went wrong"
;
}
}
$end
=
microtime
();
$end
=
microtime
();
$time
=
(
@
getMicroTime
(
$end
)
-
@
getMicroTime
(
$start
));
$time
=
(
@
getMicroTime
(
$end
)
-
@
getMicroTime
(
$start
));
if
(
$debug
)
{
if
(
$debug
)
{
echo
"<!-- Cache system by Benjamin Adams. Page generated in "
.
round
(
$time
,
5
)
.
" seconds. -->"
;
echo
"<!-- Cache system by Benjamin Adams. Page generated in "
.
round
(
$time
,
5
)
.
" seconds. -->
\n
"
;
echo
"<!-- Site was cached = "
.
$cache
.
" -->"
;
echo
"<!-- Site was cached = "
.
$cache
.
" -->
\n
"
;
echo
"<!-- wp-redis-cache-seconds = "
.
$seconds_cache_redis
.
" -->"
;
if
(
isset
(
$seconds_cache_redis
))
{
echo
"<!-- wp-redis-cache-secret = "
.
$secret_string
.
"-->"
;
echo
"<!-- wp-redis-cache-seconds = "
.
$seconds_cache_redis
.
" -->
\n
"
;
echo
"<!-- wp-redis-cache-ip = "
.
$ip_of_your_website
.
"-->"
;
}
echo
"<!-- wp-redis-cache-unlimited = "
.
$unlimited
.
"-->"
;
echo
"<!-- wp-redis-cache-secret = "
.
$secret_string
.
"-->
\n
"
;
echo
"<!-- wp-redis-cache-debug = "
.
$debug
.
"-->"
;
echo
"<!-- wp-redis-cache-ip = "
.
$websiteIp
.
"-->
\n
"
;
if
(
isset
(
$unlimited
))
{
echo
"<!-- wp-redis-cache-unlimited = "
.
$unlimited
.
"-->
\n
"
;
}
echo
"<!-- wp-redis-cache-debug = "
.
$debug
.
"-->
\n
"
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment