Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
R
Redis Page Cache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WP Plugins
Redis Page Cache
Commits
c48385e7
Commit
c48385e7
authored
Sep 09, 2013
by
Ulrich Block
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update index-wp-redis.php
parent
89c8f144
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
26 deletions
+31
-26
index-wp-redis.php
index-wp-redis.php
+31
-26
No files found.
index-wp-redis.php
View file @
c48385e7
<?php
// Start the timer so we can track the page load time
$start
=
microtime
();
function
getMicroTime
(
$t
)
{
list
(
$usec
,
$sec
)
=
explode
(
" "
,
$t
);
return
((
float
)
$usec
+
(
float
)
$sec
);
}
$seconds_cache_redis
=
60
*
60
*
12
;
// 12 hours by default, you can change in this in wp-admin options page
$ip_of_your_website
=
'
64.90.38.145
'
;
//You must set this to the IP of your website
$ip_of_your_website
=
'
127.0.0.1
'
;
//You must set this to the IP of your website
$secret_string
=
"changeme"
;
/*This is if you want to manually refresh the cache
ex: http://example.com/sample-post?refresh=changeme */
// so we don't confuse the cloudflare server
if
(
isset
(
$_SERVER
[
'HTTP_CF_CONNECTING_IP'
]))
{
$_SERVER
[
'REMOTE_ADDR'
]
=
$_SERVER
[
'HTTP_CF_CONNECTING_IP'
];
}
define
(
'WP_USE_THEMES'
,
true
);
// Start the timer so we can track the page load time
$start
=
microtime
();
include
(
"wp-content/plugins/wp-redis-cache/predis5.2.php"
);
//we need this to use Redis inside of PHP
$redis
=
new
Predis_Client
();
$current_url
=
"http://"
.
$_SERVER
[
'HTTP_HOST'
]
.
$_SERVER
[
'REQUEST_URI'
];
$current_url
=
str_replace
(
"?refresh=
$secret_string
"
,
''
,
$current_url
);
//clean up the URL
$current_url
=
str_replace
(
"&refresh=
$secret_string
"
,
''
,
$current_url
);
$redis_key
=
md5
(
$current_url
);
$redis_key
=
md5
(
$current_url
);
try
{
// check if PECL Extension is available
if
(
class_exists
(
'Redis'
))
{
$redis
=
new
Redis
();
// Sockets can be used as well '/tmp/redis.sock'
// documentation can be found at https://github.com/nicolasff/phpredis/#connection
$redis
->
connect
(
'127.0.0.1'
);
}
else
// Fallback to predis5.2.php
{
include
(
"wp-content/plugins/wp-redis-cache/predis5.2.php"
);
//we need this to use Redis inside of PHP
$redis
=
new
Predis_Client
();
}
}
catch
(
Exception
$e
)
{
$redisError
=
true
;
}
//Either manual refresh cache by adding ?refresh=secret_string after the URL or somebody posting a comment
if
(
isset
(
$_GET
[
'refresh'
])
||
$_GET
[
'refresh'
]
==
$secret_string
||
(
$_SERVER
[
'HTTP_REFERER'
]
==
$current_url
&&
$_SERVER
[
'REQUEST_URI'
]
!=
'/'
&&
$_SERVER
[
'REMOTE_ADDR'
]
!=
$ip_of_your_website
))
{
if
(
!
isset
(
$redisError
)
&&
(
isset
(
$_GET
[
'refresh'
])
||
$_GET
[
'refresh'
]
==
$secret_string
||
(
$_SERVER
[
'HTTP_REFERER'
]
==
$current_url
&&
$_SERVER
[
'REQUEST_URI'
]
!=
'/'
&&
$_SERVER
[
'REMOTE_ADDR'
]
!=
$ip_of_your_website
)
))
{
$redis
->
del
(
$redis_key
);
require
(
'./wp-blog-header.php'
);
...
...
@@ -66,10 +85,7 @@ if (isset($_GET['refresh']) || $_GET['refresh'] == $secret_string || ($_SERVER['
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'
]
!=
$ip_of_your_website
&&
strstr
(
$current_url
,
'preview=true'
)
==
true
)
||
isset
(
$redisError
))
{
require
(
'./wp-blog-header.php'
);
}
// else { // This is what your server should get if no cache exists //depricated, as the ob_start() is cleaner
...
...
@@ -84,14 +100,3 @@ if ($_SERVER['REMOTE_ADDR'] != $ip_of_your_website) {
$time
=
(
@
getMicroTime
(
$end
)
-
@
getMicroTime
(
$start
));
echo
"<!-- Cache system by Benjamin Adams. Page generated in "
.
round
(
$time
,
5
)
.
" seconds. -->"
;
}
function
getMicroTime
(
$t
)
{
list
(
$usec
,
$sec
)
=
explode
(
" "
,
$t
);
return
((
float
)
$usec
+
(
float
)
$sec
);
}
?>
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