summaryrefslogtreecommitdiffstats
path: root/php-5.5.0-opcache.patch
blob: 8ef74e9aa4af334ec45c4316a4bac185740f9b5f (plain)
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
From af967de2afc584c602c0b6d4d6731e411323d94e Mon Sep 17 00:00:00 2001
From: Dmitry Stogov <dmitry@zend.com>
Date: Wed, 10 Apr 2013 21:41:30 +0400
Subject: [PATCH] Allow wilcards in opcache.blacklist_filename

---
 ext/opcache/README                       |  8 +++----
 ext/opcache/tests/blacklist.phpt         | 20 ++++++++++++++++++
 ext/opcache/tests/opcache-1.blacklist    |  5 +++++
 ext/opcache/tests/opcache-2.blacklist    |  1 +
 ext/opcache/zend_accelerator_blacklist.c | 36 ++++++++++++++++++++++++++++++++
 5 files changed, 66 insertions(+), 4 deletions(-)
 create mode 100644 ext/opcache/tests/blacklist.phpt
 create mode 100644 ext/opcache/tests/opcache-1.blacklist
 create mode 100644 ext/opcache/tests/opcache-2.blacklist

diff --git a/ext/opcache/README b/ext/opcache/README
index 03386a0..3110012 100644
--- a/ext/opcache/README
+++ b/ext/opcache/README
@@ -151,13 +151,13 @@ opcache.dups_fix (default "0")
 	Enable this hack as a workaround for "Cannot redeclare class" errors.
 
 opcache.blacklist_filename
-	The location of the OPcache blacklist file.
-	The OPcache blacklist file is a text file that holds the names of files
+	The location of the OPcache blacklist file (wildcards allowed).
+	Each OPcache blacklist file is a text file that holds the names of files
 	that should not be accelerated. The file format is to add each filename
 	to a new line. The filename may be a full path or just a file prefix
 	(i.e., /var/www/x  blacklists all the files and directories in /var/www
-	that start with 'x'). Files are usually triggered by one of the following
-	three reasons:
+	that start with 'x'). Line starting with a ; are ignored (comments).
+	Files are usually triggered by one of the following three reasons:
 	1) Directories that contain auto generated code, like Smarty or ZFW cache.
 	2) Code that does not work well when accelerated, due to some delayed
 	   compile time evaluation.
diff --git a/ext/opcache/tests/blacklist.phpt b/ext/opcache/tests/blacklist.phpt
new file mode 100644
index 0000000..f4a3472
--- /dev/null
+++ b/ext/opcache/tests/blacklist.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Blacklist (with glob, quote and comments)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.blacklist_filename={PWD}/opcache-*.blacklist
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$conf = opcache_get_configuration();
+print_r($conf['blacklist']);
+?>
+--EXPECT--
+Array
+(
+    [0] => /path/to/foo
+    [1] => /path/to/foo2
+    [2] => /path/to/bar
+)
\ No newline at end of file
diff --git a/ext/opcache/tests/opcache-1.blacklist b/ext/opcache/tests/opcache-1.blacklist
new file mode 100644
index 0000000..5f498d6
--- /dev/null
+++ b/ext/opcache/tests/opcache-1.blacklist
@@ -0,0 +1,5 @@
+; comments are allowed in blacklist file
+; and empty line are ignored
+
+/path/to/foo
+"/path/to/foo2"
\ No newline at end of file
diff --git a/ext/opcache/tests/opcache-2.blacklist b/ext/opcache/tests/opcache-2.blacklist
new file mode 100644
index 0000000..4f6580a
--- /dev/null
+++ b/ext/opcache/tests/opcache-2.blacklist
@@ -0,0 +1 @@
+/path/to/bar
diff --git a/ext/opcache/zend_accelerator_blacklist.c b/ext/opcache/zend_accelerator_blacklist.c
index 764c950..b09d0e5 100644
--- a/ext/opcache/zend_accelerator_blacklist.c
+++ b/ext/opcache/zend_accelerator_blacklist.c
@@ -36,6 +36,14 @@
 # define REGEX_MODE (REG_EXTENDED|REG_NOSUB)
 #endif
 
+#ifdef HAVE_GLOB
+#ifdef PHP_WIN32
+#include "win32/glob.h"
+#else
+#include <glob.h>
+#endif
+#endif
+
 #define ZEND_BLACKLIST_BLOCK_SIZE	32
 
 struct _zend_regexp_list {
@@ -168,7 +176,11 @@ static inline void zend_accel_blacklist_allocate(zend_blacklist *blacklist)
 	}
 }
 
+#ifdef HAVE_GLOB
+static void zend_accel_blacklist_loadone(zend_blacklist *blacklist, char *filename)
+#else
 void zend_accel_blacklist_load(zend_blacklist *blacklist, char *filename)
+#endif
 {
 	char buf[MAXPATHLEN + 1], real_path[MAXPATHLEN + 1];
 	FILE *fp;
@@ -238,6 +250,30 @@ void zend_accel_blacklist_load(zend_blacklist *blacklist, char *filename)
 	zend_accel_blacklist_update_regexp(blacklist);
 }
 
+#ifdef HAVE_GLOB
+void zend_accel_blacklist_load(zend_blacklist *blacklist, char *filename)
+{
+	glob_t globbuf;
+	int    ret, i;
+
+	memset(&globbuf, 0, sizeof(glob_t));
+
+	ret = glob(filename, 0, NULL, &globbuf);
+#ifdef GLOB_NOMATCH
+	if (ret == GLOB_NOMATCH || !globbuf.gl_pathc) {
+#else
+	if (!globbuf.gl_pathc) {
+#endif
+		zend_accel_error(ACCEL_LOG_WARNING, "No blacklist file found matching: %s\n", filename);
+	} else {
+		for(i=0 ; i<globbuf.gl_pathc; i++) {
+			zend_accel_blacklist_loadone(blacklist, globbuf.gl_pathv[i]);
+		}
+		globfree(&globbuf);
+	}
+}
+#endif
+
 zend_bool zend_accel_blacklist_is_blacklisted(zend_blacklist *blacklist, char *verify_path)
 {
 	int ret = 0;
-- 
1.7.11.5