forked from Automattic/wp-super-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-cache-phase2.php
1461 lines (1310 loc) · 57.6 KB
/
wp-cache-phase2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
function wp_cache_phase2() {
global $cache_filename, $cache_acceptable_files, $wp_cache_gzip_encoding, $super_cache_enabled, $cache_rebuild_files, $wp_cache_last_gc;
global $cache_max_time, $wp_cache_request_uri, $super_cache_enabled, $wp_cache_object_cache, $cache_time_interval;
global $cache_enabled, $wp_cache_gmt_offset, $wp_cache_blog_charset, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval;
if ( $cache_enabled == false ) {
wp_cache_debug( "Caching disabled! quiting!", 1 );
return false;
}
wp_cache_debug( 'In WP Cache Phase 2', 5 );
$wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. http://wordpress.org/support/topic/224349
$wp_cache_blog_charset = get_option( 'blog_charset' );
wp_cache_mutex_init();
if(function_exists('add_action') && ( !defined( 'WPLOCKDOWN' ) || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) == '0' ) ) ) {
wp_cache_debug( 'Setting up WordPress actions', 5 );
add_action( 'template_redirect', 'wp_super_cache_query_vars' );
// Post ID is received
add_action('wp_trash_post', 'wp_cache_post_edit', 0);
add_action('publish_post', 'wp_cache_post_edit', 0);
add_action('edit_post', 'wp_cache_post_change', 0); // leaving a comment called edit_post
add_action('delete_post', 'wp_cache_post_edit', 0);
add_action('publish_phone', 'wp_cache_post_edit', 0);
// Coment ID is received
add_action('trackback_post', 'wp_cache_get_postid_from_comment', 99);
add_action('pingback_post', 'wp_cache_get_postid_from_comment', 99);
add_action('comment_post', 'wp_cache_get_postid_from_comment', 99);
add_action('edit_comment', 'wp_cache_get_postid_from_comment', 99);
add_action('wp_set_comment_status', 'wp_cache_get_postid_from_comment', 99, 2);
// No post_id is available
add_action('switch_theme', 'wp_cache_no_postid', 99);
add_action('edit_user_profile_update', 'wp_cache_no_postid', 99);
add_action( 'wp_update_nav_menu', 'wp_cache_clear_cache_on_menu' );
add_action('wp_cache_gc','wp_cache_gc_cron');
add_action( 'clean_post_cache', 'wp_cache_post_edit' );
add_filter( 'supercache_filename_str', 'wp_cache_check_mobile' );
add_action( 'wp_cache_gc_watcher', 'wp_cache_gc_watcher' );
add_action( 'transition_post_status', 'wpsc_post_transition', 10, 3 );
do_cacheaction( 'add_cacheaction' );
}
if ( is_admin() ) {
wp_cache_debug( 'Not caching wp-admin requests.', 5 );
return false;
}
if ( !empty( $_GET ) && !defined( "DOING_CRON" ) ) {
wp_cache_debug( 'Supercache caching disabled. Only using wp-cache. Non empty GET request. ' . json_encode( $_GET ), 5 );
$super_cache_enabled = false;
}
if($wp_cache_gzip_encoding)
header('Vary: Accept-Encoding, Cookie');
else
header('Vary: Cookie');
ob_start( 'wp_cache_ob_callback' );
wp_cache_debug( 'Created output buffer', 4 );
// restore old supercache file temporarily
if( $super_cache_enabled && $cache_rebuild_files ) {
$user_info = wp_cache_get_cookies_values();
$do_cache = apply_filters( 'do_createsupercache', $user_info );
if( $user_info == '' || $do_cache === true )
wpcache_do_rebuild( get_current_url_supercache_dir() );
}
schedule_wp_gc();
}
function wpcache_do_rebuild( $dir ) {
global $do_rebuild_list;
$dir = trailingslashit( $dir );
if ( isset( $do_rebuild_list[ $dir ] ) )
return false;
$do_rebuild_list[ $dir ] = 1;
$files_to_check = get_all_supercache_filenames( $dir );
foreach( $files_to_check as $cache_file ) {
$cache_file = $dir . $cache_file;
if( !@file_exists( $cache_file . '.needs-rebuild' ) )
continue;
$mtime = @filemtime($cache_file . '.needs-rebuild');
if( $mtime && (time() - $mtime) < 10 ) {
wp_cache_debug( "Rebuild file renamed to cache file temporarily: $cache_file", 3 );
@rename( $cache_file . '.needs-rebuild', $cache_file );
}
// cleanup old files or if rename fails
if( @file_exists( $cache_file . '.needs-rebuild' ) ) {
wp_cache_debug( "Rebuild file deleted: {$cache_file}.needs-rebuild", 3 );
@unlink( $cache_file . '.needs-rebuild' );
}
}
}
function wpcache_logged_in_message() {
echo '<!-- WP Super Cache did not cache this page because you are logged in and "Don\'t cache pages for logged in users" is enabled. -->';
}
if ( !function_exists( 'wp_cache_user_agent_is_rejected' ) ) {
function wp_cache_user_agent_is_rejected() {
global $cache_rejected_user_agent;
if (!function_exists('apache_request_headers')) return false;
$headers = apache_request_headers();
if (!isset($headers["User-Agent"])) return false;
if ( false == is_array( $cache_rejected_user_agent ) )
return false;
foreach ($cache_rejected_user_agent as $expr) {
if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
return true;
}
return false;
}
}
function wp_cache_get_response_headers() {
if(function_exists('apache_response_headers')) {
flush();
$headers = apache_response_headers();
} else if(function_exists('headers_list')) {
$headers = array();
foreach(headers_list() as $hdr) {
list($header_name, $header_value) = explode(': ', $hdr, 2);
$headers[$header_name] = $header_value;
}
} else
$headers = null;
return $headers;
}
function wp_cache_is_rejected($uri) {
global $cache_rejected_uri;
$auto_rejected = array( '/wp-admin/', 'xmlrpc.php', 'wp-app.php' );
foreach( $auto_rejected as $u ) {
if( strstr( $uri, $u ) )
return true; // we don't allow caching of wp-admin for security reasons
}
if ( false == is_array( $cache_rejected_uri ) )
return false;
foreach ( $cache_rejected_uri as $expr ) {
if( $expr != '' && @preg_match( "~$expr~", $uri ) )
return true;
}
return false;
}
function wp_cache_mutex_init() {
global $mutex, $wp_cache_mutex_disabled, $use_flock, $blog_cache_dir, $mutex_filename, $sem_id;
if( isset( $wp_cache_mutex_disabled) && $wp_cache_mutex_disabled )
return true;
if( !is_bool( $use_flock ) ) {
if(function_exists('sem_get'))
$use_flock = false;
else
$use_flock = true;
}
$mutex = false;
if ($use_flock ) {
setup_blog_cache_dir();
wp_cache_debug( "Created mutex lock on filename: {$blog_cache_dir}{$mutex_filename}", 5 );
$mutex = @fopen( $blog_cache_dir . $mutex_filename, 'w' );
} else {
wp_cache_debug( "Created mutex lock on semaphore: {$sem_id}", 5 );
$mutex = @sem_get( $sem_id, 1, 0644 | IPC_CREAT, 1 );
}
}
function wp_cache_writers_entry() {
global $mutex, $wp_cache_mutex_disabled, $use_flock;
if( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled )
return true;
if( !$mutex ) {
wp_cache_debug( "(writers entry) mutex lock not created. not caching.", 2 );
return false;
}
if ( $use_flock ) {
wp_cache_debug( "grabbing lock using flock()", 5 );
flock($mutex, LOCK_EX);
} else {
wp_cache_debug( "grabbing lock using sem_acquire()", 5 );
sem_acquire($mutex);
}
return true;
}
function wp_cache_writers_exit() {
global $mutex, $wp_cache_mutex_disabled, $use_flock;
if( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled )
return true;
if( !$mutex ) {
wp_cache_debug( "(writers exit) mutex lock not created. not caching.", 2 );
return false;
}
if ( $use_flock ) {
wp_cache_debug( "releasing lock using flock()", 5 );
flock( $mutex, LOCK_UN );
} else {
wp_cache_debug( "releasing lock using sem_release() and sem_remove()", 5 );
sem_release( $mutex );
sem_remove( $mutex );
}
}
function wp_super_cache_query_vars() {
global $wp_super_cache_query;
if ( is_search() )
$wp_super_cache_query[ 'is_search' ] = 1;
if ( is_page() )
$wp_super_cache_query[ 'is_page' ] = 1;
if ( is_archive() )
$wp_super_cache_query[ 'is_archive' ] = 1;
if ( is_tag() )
$wp_super_cache_query[ 'is_tag' ] = 1;
if ( is_single() )
$wp_super_cache_query[ 'is_single' ] = 1;
if ( is_category() )
$wp_super_cache_query[ 'is_category' ] = 1;
if ( is_front_page() )
$wp_super_cache_query[ 'is_front_page' ] = 1;
if ( is_home() )
$wp_super_cache_query[ 'is_home' ] = 1;
if ( is_author() )
$wp_super_cache_query[ 'is_author' ] = 1;
if ( is_feed() )
$wp_super_cache_query[ 'is_feed' ] = 1;
}
function wp_cache_ob_callback( $buffer ) {
global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_object_cache, $wp_cache_request_uri, $do_rebuild_list;
$buffer = apply_filters( 'wp_cache_ob_callback_filter', $buffer );
$script = basename($_SERVER['PHP_SELF']);
// All the things that can stop a page being cached
$cache_this_page = true;
if ( defined( 'DONOTCACHEPAGE' ) ) {
wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 );
$cache_this_page = false;
} elseif ( $wp_cache_no_cache_for_get && false == empty( $_GET ) && false == defined( 'DOING_CRON' ) ) {
wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . json_encode( $_GET ), 1 );
$cache_this_page = false;
} elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
wp_cache_debug( 'Not caching POST request.', 5 );
$cache_this_page = false;
} elseif ( $wp_cache_object_cache && !empty( $_GET ) ) {
wp_cache_debug( 'Not caching GET request while object cache storage enabled.', 5 );
$cache_this_page = false;
} elseif ( isset( $_GET[ 'preview' ] ) ) {
wp_cache_debug( 'Not caching preview post.', 2 );
$cache_this_page = false;
} elseif ( !in_array($script, $cache_acceptable_files) && wp_cache_is_rejected( $wp_cache_request_uri ) ) {
wp_cache_debug( 'URI rejected. Not Caching', 2 );
$cache_this_page = false;
} elseif ( wp_cache_user_agent_is_rejected() ) {
wp_cache_debug( "USER AGENT ({$_SERVER[ 'HTTP_USER_AGENT' ]}) rejected. Not Caching", 4 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'single' ] ) && $wp_cache_pages[ 'single' ] == 1 && isset( $wp_super_cache_query[ 'is_single' ] ) ) {
wp_cache_debug( 'Not caching single post.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'pages' ] ) && $wp_cache_pages[ 'pages' ] == 1 && isset( $wp_super_cache_query[ 'is_page' ] ) ) {
wp_cache_debug( 'Not caching single page.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'archives' ] ) && $wp_cache_pages[ 'archives' ] == 1 && isset( $wp_super_cache_query[ 'is_archive' ] ) ) {
wp_cache_debug( 'Not caching archive page.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'tag' ] ) && $wp_cache_pages[ 'tag' ] == 1 && isset( $wp_super_cache_query[ 'is_tag' ] ) ) {
wp_cache_debug( 'Not caching tag page.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'category' ] ) && $wp_cache_pages[ 'category' ] == 1 && isset( $wp_super_cache_query[ 'is_category' ] ) ) {
wp_cache_debug( 'Not caching category page.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'frontpage' ] ) && $wp_cache_pages[ 'frontpage' ] == 1 && isset( $wp_super_cache_query[ 'is_front_page' ] ) ) {
wp_cache_debug( 'Not caching front page.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'home' ] ) && $wp_cache_pages[ 'home' ] == 1 && isset( $wp_super_cache_query[ 'is_home' ] ) ) {
wp_cache_debug( 'Not caching home page.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'search' ] ) && $wp_cache_pages[ 'search' ] == 1 && isset( $wp_super_cache_query[ 'is_search' ] ) ) {
wp_cache_debug( 'Not caching search page.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'author' ] ) && $wp_cache_pages[ 'author' ] == 1 && isset( $wp_super_cache_query[ 'is_author' ] ) ) {
wp_cache_debug( 'Not caching author page.', 2 );
$cache_this_page = false;
} elseif ( isset( $wp_cache_pages[ 'feed' ] ) && $wp_cache_pages[ 'feed' ] == 1 && isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
wp_cache_debug( 'Not caching feed.', 2 );
$cache_this_page = false;
}
if ( !isset( $wp_query ) )
wp_cache_debug( 'wp_cache_ob_callback: WARNING! $query not defined but the plugin has worked around that problem.', 4 );
if ( $cache_this_page ) {
wp_cache_debug( 'Output buffer callback', 4 );
$buffer = wp_cache_get_ob( $buffer );
wp_cache_shutdown_callback();
return $buffer;
} else {
if ( is_array( $do_rebuild_list ) && false == empty( $do_rebuild_list ) ) {
foreach( $do_rebuild_list as $dir => $n ) {
if ( wp_cache_confirm_delete( $dir ) ) {
wp_cache_debug( 'wp_cache_ob_callback clearing rebuilt files in ' . $dir );
$files_to_check = get_all_supercache_filenames( $dir );
foreach( $files_to_check as $cache_file ) {
$cache_file = $dir . $cache_file;
@unlink( $cache_file );
}
}
}
}
return wp_cache_maybe_dynamic( $buffer );
}
}
function wp_cache_append_tag( &$buffer ) {
global $wp_cache_gmt_offset, $wp_super_cache_comments;
global $cache_enabled, $super_cache_enabled;
if ( false == isset( $wp_super_cache_comments ) )
$wp_super_cache_comments = 1;
if ( $wp_super_cache_comments == 0 )
return false;
$timestamp = gmdate('Y-m-d H:i:s', (time() + ( $wp_cache_gmt_offset * 3600)));
if ( $cache_enabled || $super_cache_enabled ) {
$buffer .= "\n<!-- Cached page generated by WP-Super-Cache on $timestamp -->\n";
} else {
$buffer .= "\n<!-- Live page served on $timestamp -->\n";
}
}
function wp_cache_add_to_buffer( &$buffer, $text ) {
global $wp_super_cache_comments;
if ( false == isset( $wp_super_cache_comments ) )
$wp_super_cache_comments = 1;
if ( $wp_super_cache_comments == 0 )
return false;
$buffer .= "\n<!-- $text -->";
}
/*
* If dynamic caching is enabled then run buffer through wpsc_cachedata filter before returning it.
* or we'll return template tags to visitors.
*/
function wp_cache_maybe_dynamic( &$buffer ) {
global $wp_cache_mfunc_enabled;
if ( $wp_cache_mfunc_enabled == 1 && do_cacheaction( 'wpsc_cachedata_safety', 0 ) === 1 ) {
wp_cache_debug( 'wp_cache_maybe_dynamic: filtered $buffer through wpsc_cachedata', 4 );
return do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display
} else {
wp_cache_debug( 'wp_cache_maybe_dynamic: returned $buffer', 4 );
return $buffer;
}
}
function wp_cache_get_ob(&$buffer) {
global $cache_enabled, $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir;
global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression;
global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages;
global $wp_cache_404, $gzsize, $supercacheonly;
global $blog_cache_dir, $wp_cache_request_uri, $wp_supercache_cache_list;
global $wp_cache_not_logged_in, $wp_cache_object_cache, $cache_max_time;
global $wp_cache_is_home, $wp_cache_front_page_checks, $wp_cache_mfunc_enabled, $wp_super_cache_send_link_headers;
if ( isset( $wp_cache_mfunc_enabled ) == false )
$wp_cache_mfunc_enabled = 0;
$new_cache = true;
$wp_cache_meta = '';
/* Mode paranoic, check for closing tags
* we avoid caching incomplete files */
if ( $buffer == '' ) {
$new_cache = false;
if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
wp_cache_debug( "Buffer is blank. Output buffer may have been corrupted by another plugin or this is a redirected URL. Look for text 'ob_start' in the files of your plugins directory.", 2 );
wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Blank Page. Check output buffer usage by plugins." );
}
}
if ( $wp_cache_404 && false == apply_filters( 'wpsupercache_404', false ) ) {
$new_cache = false;
if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
wp_cache_debug( "404 file not found not cached", 2 );
wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. 404." );
}
}
if ( !preg_match( apply_filters( 'wp_cache_eof_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) {
$new_cache = false;
if( false === strpos( $_SERVER[ 'REQUEST_URI' ], 'robots.txt' ) ) {
if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
wp_cache_debug( "No closing html tag. Not caching.", 2 );
wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. No closing HTML tag. Check your theme." );
}
} else {
wp_cache_debug( "robots.txt detected. Not caching.", 2 );
}
}
if( !$new_cache )
return wp_cache_maybe_dynamic( $buffer );
$duration = wp_cache_microtime_diff($wp_start_time, microtime());
$duration = sprintf("%0.3f", $duration);
wp_cache_add_to_buffer( $buffer, "Dynamic page generated in $duration seconds." );
if( !wp_cache_writers_entry() ) {
wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Could not get mutex lock." );
wp_cache_debug( "Could not get mutex lock. Not caching.", 1 );
return wp_cache_maybe_dynamic( $buffer );
}
if ( $wp_cache_not_logged_in && is_feed() ) {
wp_cache_debug( "Feed detected. Writing legacy cache files.", 5 );
$wp_cache_not_logged_in = false;
}
$home_url = parse_url( trailingslashit( get_bloginfo( 'url' ) ) );
$dir = get_current_url_supercache_dir();
$supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url[ 'host' ]);
if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) {
wp_cache_debug( "Supercache disabled: GET or feed detected or disabled by config.", 2 );
$super_cache_enabled = false;
}
$tmp_wpcache_filename = $cache_path . uniqid( mt_rand(), true ) . '.tmp';
$supercacheonly = false;
if( $super_cache_enabled ) {
if ( wp_cache_get_cookies_values() == '' && empty( $_GET ) ) {
wp_cache_debug( "Anonymous user detected. Only creating Supercache file.", 3 );
$supercacheonly = true;
}
}
$cache_error = '';
if ( $wp_cache_not_logged_in && wp_cache_get_cookies_values() != '' ) {
$super_cache_enabled = false;
$cache_enabled = false;
$cache_error = 'Not caching requests by known users. (See Advanced Settings page)';
wp_cache_debug( 'Not caching for known user.', 5 );
}
if ( $wp_cache_object_cache ) { // half on mode when using the object cache
if ( wp_cache_get_cookies_values() != '' ) {
$cache_enabled = false;
$cache_error = 'Known User and using object. Only anonymous users cached.';
}
$super_cache_enabled = false;
$supercacheonly = false;
wp_cache_init(); // PHP5 destroys objects during shutdown
}
if ( !$cache_enabled ) {
wp_cache_debug( 'Cache is not enabled. Sending buffer to browser.', 5 );
wp_cache_writers_exit();
wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Check your settings page. $cache_error" );
if ( $wp_cache_mfunc_enabled == 1 ) {
global $wp_super_cache_late_init;
if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) )
wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details.' );
}
return wp_cache_maybe_dynamic( $buffer );
}
if( @is_dir( $dir ) == false )
@wp_mkdir_p( $dir );
$fr = $fr2 = $gz = false;
// Open wp-cache cache file
if ( false == $wp_cache_object_cache ) {
if ( !$supercacheonly ) {
$fr = @fopen($tmp_wpcache_filename, 'w');
if (!$fr) {
wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename, 1 );
wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename );
wp_cache_writers_exit();
return wp_cache_maybe_dynamic( $buffer );
}
} else {
$user_info = wp_cache_get_cookies_values();
$do_cache = apply_filters( 'do_createsupercache', $user_info );
if ( $super_cache_enabled && ( $user_info == '' || $do_cache === true ) ) {
$cache_fname = $dir . supercache_filename();
$tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
$fr2 = @fopen( $tmp_cache_filename, 'w' );
if ( !$fr2 ) {
wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 );
wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) );
@fclose( $fr );
@unlink( $tmp_wpcache_filename );
wp_cache_writers_exit();
return wp_cache_maybe_dynamic( $buffer );
} elseif ( ( !isset( $wp_cache_mfunc_enabled ) || $wp_cache_mfunc_enabled == 0 ) && $cache_compression ) { // don't want to store compressed files if using dynamic content
$gz = @fopen( $tmp_cache_filename . ".gz", 'w');
if (!$gz) {
wp_cache_debug( "Error. Supercache could not write to " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz", 1 );
wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz" );
@fclose( $fr );
@unlink( $tmp_wpcache_filename );
@fclose( $fr2 );
@unlink( $tmp_cache_filename );
wp_cache_writers_exit();
return wp_cache_maybe_dynamic( $buffer );
}
}
}
}
}
$added_cache = 0;
$oc_key = get_oc_key();
$buffer = apply_filters( 'wpsupercache_buffer', $buffer );
wp_cache_append_tag( $buffer );
if ($wp_super_cache_send_link_headers) {
wp_cache_http2_preload_headers($buffer);
}
/*
* Dynamic content enabled: write the buffer to a file and then process any templates found using
* the wpsc_cachedata filter. Buffer is then returned to the visitor.
*/
if ( $wp_cache_mfunc_enabled == 1 ) {
if ( preg_match( '/<!--mclude|<!--mfunc|<!--dynamic-cached-content-->/', $buffer ) ) { //Dynamic content
wp_cache_debug( "mfunc/mclude/dynamic-cached-content tags have been retired. Please update your theme. See docs for updates." );
wp_cache_add_to_buffer( $buffer, "Warning! Obsolete mfunc/mclude/dynamic-cached-content tags found. Please update your theme. See http://ocaoimh.ie/y/5b for more information." );
}
global $wp_super_cache_late_init;
if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) )
wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but late init not set. See the readme.txt for further details.' );
if ( $fr ) { // legacy caching
wp_cache_debug( "Writing dynamic buffer to legacy file." );
wp_cache_add_to_buffer( $buffer, "Dynamic Legacy Super Cache" );
fputs( $fr, '<?php die(); ?>' . $buffer );
} elseif ( isset( $fr2 ) ) { // supercache active
wp_cache_debug( "Writing dynamic buffer to supercache file." );
wp_cache_add_to_buffer( $buffer, "Dynamic Super Cache" );
fputs( $fr2, $buffer );
} elseif ( true == $wp_cache_object_cache ) {
wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time );
}
$wp_cache_meta[ 'dynamic' ] = true;
if ( do_cacheaction( 'wpsc_cachedata_safety', 0 ) === 1 )
$buffer = do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display
if ( $cache_compression && $wp_cache_gzip_encoding ) {
wp_cache_debug( "Gzipping dynamic buffer for display.", 5 );
wp_cache_add_to_buffer( $buffer, "Compression = gzip" );
$gzdata = gzencode( $buffer, 6, FORCE_GZIP );
$gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata );
}
} else {
if ( $gz || $wp_cache_gzip_encoding ) {
wp_cache_debug( "Gzipping buffer.", 5 );
wp_cache_add_to_buffer( $buffer, "Compression = gzip" );
$gzdata = gzencode( $buffer, 6, FORCE_GZIP );
$gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata );
$wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
$wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie';
// Return uncompressed data & store compressed for later use
if ( $fr ) {
wp_cache_debug( "Writing gzipped buffer to wp-cache cache file.", 5 );
fputs($fr, '<?php die(); ?>' . $gzdata);
} elseif ( $cache_enabled && $wp_cache_object_cache ) {
wp_cache_set( $oc_key . ".gz", $gzdata, 'supercache', $cache_max_time );
$added_cache = 1;
}
} else { // no compression
$wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Cookie';
if ( $cache_enabled && $wp_cache_object_cache ) {
wp_cache_set( $oc_key, $buffer, 'supercache', $cache_max_time );
$added_cache = 1;
} elseif ( $fr ) {
wp_cache_debug( "Writing non-gzipped buffer to wp-cache cache file." );
fputs($fr, '<?php die(); ?>' . $buffer);
}
}
if ( $fr2 ) {
wp_cache_debug( "Writing non-gzipped buffer to supercache file." );
wp_cache_add_to_buffer( $buffer, "super cache" );
fputs($fr2, $buffer );
}
if ( isset( $gzdata ) && $gz ) {
wp_cache_debug( "Writing gzipped buffer to supercache file." );
fwrite($gz, $gzdata );
}
}
$new_cache = true;
if ( false == $wp_cache_object_cache ) {
if( $fr ) {
$supercacheonly = false;
fclose($fr);
if ( filesize( $tmp_wpcache_filename ) == 0 ) {
wp_cache_debug( "Warning! The file $tmp_wpcache_filename was empty. Did not rename to {$blog_cache_dir}{$cache_filename}", 5 );
@unlink( $tmp_wpcache_filename );
} else {
if ( !@rename( $tmp_wpcache_filename, $blog_cache_dir . $cache_filename ) ) {
if ( false == is_dir( $blog_cache_dir ) )
@wp_mkdir_p( $blog_cache_dir );
@unlink( $blog_cache_dir . $cache_filename );
@rename( $tmp_wpcache_filename, $blog_cache_dir . $cache_filename );
}
wp_cache_debug( "Renamed temp wp-cache file to {$blog_cache_dir}$cache_filename", 5 );
$added_cache = 1;
}
}
if( $fr2 ) {
fclose($fr2);
if ( $wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url[ 'path' ] . supercache_filename() && !( $wp_cache_is_home ) ) {
wp_cache_writers_exit();
wp_cache_debug( "Warning! Not writing another page to front page cache.", 1 );
return $buffer;
} elseif ( filesize( $tmp_cache_filename ) == 0 ) {
wp_cache_debug( "Warning! The file $tmp_cache_filename was empty. Did not rename to {$cache_fname}", 5 );
@unlink( $tmp_cache_filename );
} else {
if ( !@rename( $tmp_cache_filename, $cache_fname ) ) {
@unlink( $cache_fname );
@rename( $tmp_cache_filename, $cache_fname );
}
wp_cache_debug( "Renamed temp supercache file to $cache_fname", 5 );
$added_cache = 1;
}
}
if( $gz ) {
fclose($gz);
if ( filesize( $tmp_cache_filename . '.gz' ) == 0 ) {
wp_cache_debug( "Warning! The file {$tmp_cache_filename}.gz was empty. Did not rename to {$cache_fname}.gz", 5 );
@unlink( $tmp_cache_filename . '.gz' );
} else {
if ( !@rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' ) ) {
@unlink( $cache_fname . '.gz' );
@rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' );
}
wp_cache_debug( "Renamed temp supercache gz file to {$cache_fname}.gz", 5 );
$added_cache = 1;
}
}
}
if ( $added_cache && isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) {
update_option( 'wpsupercache_count', ( get_option( 'wpsupercache_count' ) + 1 ) );
$last_urls = (array)get_option( 'supercache_last_cached' );
if ( count( $last_urls ) >= 10 )
$last_urls = array_slice( $last_urls, 1, 9 );
$last_urls[] = array( 'url' => preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] ), 'date' => date( 'Y-m-d H:i:s' ) );
update_option( 'supercache_last_cached', $last_urls );
}
wp_cache_writers_exit();
if ( !headers_sent() && $wp_cache_gzip_encoding && $gzdata) {
wp_cache_debug( "Writing gzip content headers. Sending buffer to browser", 5 );
header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
header( 'Vary: Accept-Encoding, Cookie' );
header( 'Content-Length: ' . $gzsize );
return $gzdata;
} else {
wp_cache_debug( "Sending buffer to browser", 5 );
return $buffer;
}
}
function wp_cache_http2_preload_headers($puffer)
{
if (!headers_sent()) {
preg_match_all('/<link\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*(.*)\/>/siU', $puffer, $styleSheets);
preg_match_all('/<img\s[^>]*src=(\"??)([^\" >]*?)\\1[^>]*(.*)\/>/siU', $puffer, $images);
preg_match_all('/<script\s[^>]*src=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/script>/siU', $puffer, $javaScripts);
$header = 'Link: ';
//css
if (is_array($styleSheets[2])) {
foreach ($styleSheets[2] as $preloadLink) {
if (strpos($preloadLink, '.css') && wp_cache_url_prealoadable($preloadLink)) {
header('Link: <'.wp_cache_url_prealoadable($preloadLink).'>; rel=preload; as=stylesheet', false);
}
}
}
//javascript
if (is_array($javaScripts[2])) {
foreach ($javaScripts[2] as $preloadLink) {
if (strpos($preloadLink, '.js') && wp_cache_url_prealoadable($preloadLink)) {
header('Link: <'.wp_cache_url_prealoadable($preloadLink).'>; rel=preload; as=script', false);
}
}
}
//images
if (is_array($images[2])) {
foreach ($images[2] as $preloadLink) {
if (wp_cache_url_prealoadable($preloadLink)) {
header('Link: <'.wp_cache_url_prealoadable($preloadLink).'>; rel=preload; as=image', false);
}
}
}
}
}
function wp_cache_url_prealoadable($url) {
$url = str_replace(["'", '"'], '', $url);
if (!strlen($url)) {
return false;
}
if (substr($url, 0, 1) == '/') {
return $url;
}
else if (strpos($url, '://' . $_SERVER['HTTP_HOST'])) {
return $url;
}
return false;
}
function wp_cache_phase2_clean_cache($file_prefix) {
global $cache_path, $blog_cache_dir;
if( !wp_cache_writers_entry() )
return false;
wp_cache_debug( "wp_cache_phase2_clean_cache: Cleaning cache in $blog_cache_dir" );
if ( $handle = @opendir( $blog_cache_dir ) ) {
while ( false !== ($file = @readdir($handle))) {
if ( strpos( $file, $file_prefix ) !== false ) {
if ( strpos( $file, '.html' ) ) {
// delete old legacy files immediately
wp_cache_debug( "wp_cache_phase2_clean_cache: Deleting obsolete legacy cache+meta files: $file" );
@unlink( $blog_cache_dir . $file);
@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
} else {
$meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
if ( $meta[ 'blog_id' ] == $wpdb->blogid ) {
@unlink( $blog_cache_dir . $file );
@unlink( $blog_cache_dir . 'meta/' . $file );
}
}
}
}
closedir($handle);
}
wp_cache_writers_exit();
}
function prune_super_cache( $directory, $force = false, $rename = false ) {
global $cache_max_time, $cache_path, $cache_rebuild_files, $blog_cache_dir;
static $log = 0;
if ( false == @file_exists( $directory ) ) {
wp_cache_debug( "prune_super_cache: exiting as file/dir does not exist: $directory" );
return $log;
}
if( !isset( $cache_max_time ) )
$cache_max_time = 3600;
$now = time();
$protected_directories = array( $cache_path . '.htaccess',
$cache_path . "index.html",
$cache_path . $blog_cache_dir,
$cache_path . $blog_cache_dir . "index.html",
$cache_path . $blog_cache_dir . 'meta',
$cache_path . $blog_cache_dir . 'meta/index.html',
$cache_path . 'supercache/index.html',
$cache_path . 'supercache' );
$oktodelete = false;
if (is_dir($directory)) {
if( $dh = @opendir( $directory ) ) {
$directory = trailingslashit( $directory );
while( ( $entry = @readdir( $dh ) ) !== false ) {
if ($entry == '.' || $entry == '..')
continue;
$entry = $directory . $entry;
prune_super_cache( $entry, $force, $rename );
// If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date,
if( is_dir( $entry ) && !in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
// if the directory isn't empty can't delete it
if( $handle = @opendir( $entry ) ) {
$donotdelete = false;
while( !$donotdelete && ( $file = @readdir( $handle ) ) !== false ) {
if ($file == '.' || $file == '..')
continue;
$donotdelete = true;
wp_cache_debug( "gc: could not delete $entry as it's not empty: $file", 2 );
}
closedir($handle);
}
if( $donotdelete )
continue;
if( !$rename ) {
@rmdir( $entry );
$log++;
if ( $force ) {
wp_cache_debug( "gc: deleted $entry, forced delete", 2 );
} else {
wp_cache_debug( "gc: deleted $entry, older than $cache_max_time seconds", 2 );
}
}
} elseif ( in_array( $entry, $protected_directories ) ) {
wp_cache_debug( "gc: could not delete $entry as it's protected.", 2 );
}
}
closedir($dh);
}
} elseif( is_file($directory) && ($force || @filemtime( $directory ) + $cache_max_time <= $now ) ) {
$oktodelete = true;
if ( in_array( $directory, $protected_directories ) ) {
wp_cache_debug( "gc: could not delete $directory as it's protected.", 2 );
$oktodelete = false;
}
if( $oktodelete && !$rename ) {
wp_cache_debug( "prune_super_cache: deleted $directory", 5 );
@unlink( $directory );
$log++;
} elseif( $oktodelete && $rename ) {
wp_cache_debug( "prune_super_cache: wp_cache_rebuild_or_delete( $directory )", 5 );
wp_cache_rebuild_or_delete( $directory );
$log++;
} else {
wp_cache_debug( "prune_super_cache: did not delete file: $directory" );
}
} else {
wp_cache_debug( "prune_super_cache: did not delete file as it wasn't a directory or file and not forced to delete new file: $directory" );
}
return $log;
}
function wp_cache_rebuild_or_delete( $file ) {
global $cache_rebuild_files;
if( strpos( $file, '?' ) !== false )
$file = substr( $file, 0, strpos( $file, '?' ) );
if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
if( @rename($file, $file . '.needs-rebuild') ) {
@touch( $file . '.needs-rebuild' );
wp_cache_debug( "rebuild_or_gc: rename file to {$file}.needs-rebuild", 2 );
} else {
@unlink( $file );
wp_cache_debug( "rebuild_or_gc: deleted $file", 2 );
}
} else {
@unlink( $file );
wp_cache_debug( "rebuild_or_gc: deleted $file", 2 );
}
}
function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) {
global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
clearstatcache();
if( !wp_cache_writers_entry() )
return false;
$now = time();
wp_cache_debug( "Cleaning expired cache files in $blog_cache_dir", 2 );
$deleted = 0;
if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
while ( false !== ($file = readdir($handle))) {
if ( preg_match("/^$file_prefix/", $file) &&
(@filemtime( $blog_cache_dir . $file) + $cache_max_time) <= $now ) {
@unlink( $blog_cache_dir . $file );
@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
wp_cache_debug( "wp_cache_phase2_clean_expired: Deleting obsolete legacy cache+meta files: $file" );
continue;
}
if($file != '.' && $file != '..') {
if( is_dir( $blog_cache_dir . $file ) == false && (@filemtime($blog_cache_dir . $file) + $cache_max_time) <= $now ) {
if ( substr( $file, -9 ) != '.htaccess' && $file != 'index.html' ) {
@unlink($blog_cache_dir . $file);
wp_cache_debug( "Deleting $blog_cache_dir{$file}, older than $cache_max_time seconds", 5 );
}
}
}
}
closedir($handle);
if ( false == $wp_cache_preload_on || true == $force ) {
wp_cache_debug( "Doing GC on supercache dir: {$cache_path}supercache", 2 );
$deleted = prune_super_cache( $cache_path . 'supercache', false, false );
}
}
wp_cache_writers_exit();
return $deleted;
}
function wp_cache_shutdown_callback() {
global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache, $wp_cache_meta, $known_headers, $blog_id, $wp_cache_gzip_encoding, $gzsize, $cache_filename, $supercacheonly, $blog_cache_dir;
global $wp_cache_request_uri, $wp_cache_key, $wp_cache_object_cache, $cache_enabled, $wp_cache_blog_charset, $wp_cache_not_logged_in;
global $WPSC_HTTP_HOST;
$wp_cache_meta[ 'uri' ] = $WPSC_HTTP_HOST . preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $wp_cache_request_uri); // To avoid XSS attacks
$wp_cache_meta[ 'blog_id' ] = $blog_id;
$wp_cache_meta[ 'post' ] = wp_cache_post_id();
$wp_cache_meta[ 'key' ] = $wp_cache_key;
$wp_cache_meta = apply_filters( 'wp_cache_meta', $wp_cache_meta );
$response = wp_cache_get_response_headers();
foreach ($known_headers as $key) {
if(isset($response[$key])) {
$wp_cache_meta[ 'headers' ][ $key ] = "$key: " . $response[$key];
}
}
wp_cache_debug( "wp_cache_shutdown_callback: collecting meta data.", 2 );
if (!isset( $response['Last-Modified'] )) {
$value = gmdate('D, d M Y H:i:s') . ' GMT';
/* Dont send this the first time */
/* @header('Last-Modified: ' . $value); */
$wp_cache_meta[ 'headers' ][ 'Last-Modified' ] = "Last-Modified: $value";
}
if ( !isset( $response[ 'Content-Type' ] ) && !isset( $response[ 'Content-type' ] ) ) {
// On some systems, headers set by PHP can't be fetched from
// the output buffer. This is a last ditch effort to set the
// correct Content-Type header for feeds, if we didn't see
// it in the response headers already. -- dougal
if (is_feed()) {
$type = get_query_var('feed');
$type = str_replace('/','',$type);
switch ($type) {
case 'atom':
$value = "application/atom+xml";
break;
case 'rdf':
$value = "application/rdf+xml";
break;
case 'rss':
case 'rss2':
default:
$value = "application/rss+xml";
}
} else { // not a feed
$value = get_option( 'html_type' );
if( $value == '' )
$value = 'text/html';
}
$value .= "; charset=\"" . $wp_cache_blog_charset . "\"";
wp_cache_debug( "Sending 'Content-Type: $value' header.", 2 );
@header("Content-Type: $value");
$wp_cache_meta[ 'headers' ][ 'Content-Type' ] = "Content-Type: $value";
}
if ( $cache_enabled && !$supercacheonly && $new_cache ) {
if( !isset( $wp_cache_meta[ 'dynamic' ] ) && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta[ 'headers' ] ) ) {
wp_cache_debug( "Sending gzip headers.", 2 );
$wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
$wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie';
}
$serial = '<?php die(); ?>' . json_encode( $wp_cache_meta );
if( wp_cache_writers_entry() ) {
wp_cache_debug( "Writing meta file: {$blog_cache_dir}meta/{$meta_file}", 2 );
if ( false == $wp_cache_object_cache ) {
$tmp_meta_filename = $blog_cache_dir . 'meta/' . uniqid( mt_rand(), true ) . '.tmp';
$fr = @fopen( $tmp_meta_filename, 'w');
if( !$fr )
@wp_mkdir_p( $blog_cache_dir . 'meta' );
$fr = @fopen( $tmp_meta_filename, 'w');
if ( $fr ) {
fputs($fr, $serial);
fclose($fr);
@chmod( $tmp_meta_filename, 0666 & ~umask());
if( !@rename( $tmp_meta_filename, $blog_cache_dir . 'meta/' . $meta_file ) ) {
@unlink( $blog_cache_dir . 'meta/' . $meta_file );
@rename( $tmp_meta_filename, $blog_cache_dir . 'meta/' . $meta_file );
}
} else {
wp_cache_debug( "Problem writing meta file: {$blog_cache_dir}meta/{$meta_file}", 2 );
}