1PHP_ARG_ENABLE([opcache], 2 [whether to enable Zend OPcache support], 3 [AS_HELP_STRING([--disable-opcache], 4 [Disable Zend OPcache support])], 5 [yes]) 6 7PHP_ARG_ENABLE([huge-code-pages], 8 [whether to enable copying PHP CODE pages into HUGE PAGES], 9 [AS_HELP_STRING([--disable-huge-code-pages], 10 [Disable copying PHP CODE pages into HUGE PAGES])], 11 [yes], 12 [no]) 13 14if test "$PHP_OPCACHE" != "no"; then 15 16 dnl Always build as shared extension 17 ext_shared=yes 18 19 if test "$PHP_HUGE_CODE_PAGES" = "yes"; then 20 AC_DEFINE(HAVE_HUGE_CODE_PAGES, 1, [Define to enable copying PHP CODE pages into HUGE PAGES (experimental)]) 21 fi 22 23 AC_CHECK_FUNCS([mprotect]) 24 25 AC_MSG_CHECKING(for sysvipc shared memory support) 26 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 27#include <sys/types.h> 28#include <sys/wait.h> 29#include <sys/ipc.h> 30#include <sys/shm.h> 31#include <unistd.h> 32#include <string.h> 33 34int main() { 35 pid_t pid; 36 int status; 37 int ipc_id; 38 char *shm; 39 struct shmid_ds shmbuf; 40 41 ipc_id = shmget(IPC_PRIVATE, 4096, (IPC_CREAT | SHM_R | SHM_W)); 42 if (ipc_id == -1) { 43 return 1; 44 } 45 46 shm = shmat(ipc_id, NULL, 0); 47 if (shm == (void *)-1) { 48 shmctl(ipc_id, IPC_RMID, NULL); 49 return 2; 50 } 51 52 if (shmctl(ipc_id, IPC_STAT, &shmbuf) != 0) { 53 shmdt(shm); 54 shmctl(ipc_id, IPC_RMID, NULL); 55 return 3; 56 } 57 58 shmbuf.shm_perm.uid = getuid(); 59 shmbuf.shm_perm.gid = getgid(); 60 shmbuf.shm_perm.mode = 0600; 61 62 if (shmctl(ipc_id, IPC_SET, &shmbuf) != 0) { 63 shmdt(shm); 64 shmctl(ipc_id, IPC_RMID, NULL); 65 return 4; 66 } 67 68 shmctl(ipc_id, IPC_RMID, NULL); 69 70 strcpy(shm, "hello"); 71 72 pid = fork(); 73 if (pid < 0) { 74 return 5; 75 } else if (pid == 0) { 76 strcpy(shm, "bye"); 77 return 6; 78 } 79 if (wait(&status) != pid) { 80 return 7; 81 } 82 if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) { 83 return 8; 84 } 85 if (strcmp(shm, "bye") != 0) { 86 return 9; 87 } 88 return 0; 89} 90]])],[dnl 91 AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support]) 92 msg=yes],[msg=no],[msg=no]) 93 AC_MSG_RESULT([$msg]) 94 95 AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support) 96 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 97#include <sys/types.h> 98#include <sys/wait.h> 99#include <sys/mman.h> 100#include <unistd.h> 101#include <string.h> 102 103#ifndef MAP_ANON 104# ifdef MAP_ANONYMOUS 105# define MAP_ANON MAP_ANONYMOUS 106# endif 107#endif 108#ifndef MAP_FAILED 109# define MAP_FAILED ((void*)-1) 110#endif 111 112int main() { 113 pid_t pid; 114 int status; 115 char *shm; 116 117 shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 118 if (shm == MAP_FAILED) { 119 return 1; 120 } 121 122 strcpy(shm, "hello"); 123 124 pid = fork(); 125 if (pid < 0) { 126 return 5; 127 } else if (pid == 0) { 128 strcpy(shm, "bye"); 129 return 6; 130 } 131 if (wait(&status) != pid) { 132 return 7; 133 } 134 if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) { 135 return 8; 136 } 137 if (strcmp(shm, "bye") != 0) { 138 return 9; 139 } 140 return 0; 141} 142]])],[dnl 143 AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support]) 144 msg=yes],[msg=no],[msg=no]) 145 AC_MSG_RESULT([$msg]) 146 147 PHP_CHECK_FUNC_LIB(shm_open, rt) 148 AC_MSG_CHECKING(for mmap() using shm_open() shared memory support) 149 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 150#include <sys/types.h> 151#include <sys/wait.h> 152#include <sys/mman.h> 153#include <sys/stat.h> 154#include <fcntl.h> 155#include <unistd.h> 156#include <string.h> 157#include <stdlib.h> 158#include <stdio.h> 159 160#ifndef MAP_FAILED 161# define MAP_FAILED ((void*)-1) 162#endif 163 164int main() { 165 pid_t pid; 166 int status; 167 int fd; 168 char *shm; 169 char tmpname[4096]; 170 171 sprintf(tmpname,"/opcache.test.shm.%dXXXXXX", getpid()); 172 if (mktemp(tmpname) == NULL) { 173 return 1; 174 } 175 fd = shm_open(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 176 if (fd == -1) { 177 return 2; 178 } 179 if (ftruncate(fd, 4096) < 0) { 180 close(fd); 181 shm_unlink(tmpname); 182 return 3; 183 } 184 185 shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 186 if (shm == MAP_FAILED) { 187 return 4; 188 } 189 shm_unlink(tmpname); 190 close(fd); 191 192 strcpy(shm, "hello"); 193 194 pid = fork(); 195 if (pid < 0) { 196 return 5; 197 } else if (pid == 0) { 198 strcpy(shm, "bye"); 199 return 6; 200 } 201 if (wait(&status) != pid) { 202 return 7; 203 } 204 if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) { 205 return 8; 206 } 207 if (strcmp(shm, "bye") != 0) { 208 return 9; 209 } 210 return 0; 211} 212]])],[dnl 213 AC_DEFINE(HAVE_SHM_MMAP_POSIX, 1, [Define if you have POSIX mmap() SHM support]) 214 AC_MSG_RESULT([yes]) 215 PHP_CHECK_LIBRARY(rt, shm_unlink, [PHP_ADD_LIBRARY(rt,1,OPCACHE_SHARED_LIBADD)]) 216 ],[ 217 AC_MSG_RESULT([no]) 218 ],[ 219 AC_MSG_RESULT([no]) 220 ]) 221 222 PHP_NEW_EXTENSION(opcache, 223 ZendAccelerator.c \ 224 zend_accelerator_blacklist.c \ 225 zend_accelerator_debug.c \ 226 zend_accelerator_hash.c \ 227 zend_accelerator_module.c \ 228 zend_persist.c \ 229 zend_persist_calc.c \ 230 zend_file_cache.c \ 231 zend_shared_alloc.c \ 232 zend_accelerator_util_funcs.c \ 233 shared_alloc_shm.c \ 234 shared_alloc_mmap.c \ 235 shared_alloc_posix.c \ 236 Optimizer/zend_optimizer.c \ 237 Optimizer/pass1_5.c \ 238 Optimizer/pass2.c \ 239 Optimizer/pass3.c \ 240 Optimizer/optimize_func_calls.c \ 241 Optimizer/block_pass.c \ 242 Optimizer/optimize_temp_vars_5.c \ 243 Optimizer/nop_removal.c \ 244 Optimizer/compact_literals.c \ 245 Optimizer/zend_cfg.c \ 246 Optimizer/zend_dfg.c \ 247 Optimizer/dfa_pass.c \ 248 Optimizer/zend_ssa.c \ 249 Optimizer/zend_inference.c \ 250 Optimizer/zend_func_info.c \ 251 Optimizer/zend_call_graph.c \ 252 Optimizer/sccp.c \ 253 Optimizer/scdf.c \ 254 Optimizer/dce.c \ 255 Optimizer/escape_analysis.c \ 256 Optimizer/compact_vars.c \ 257 Optimizer/zend_dump.c, 258 shared,,-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1,,yes) 259 260 PHP_ADD_BUILD_DIR([$ext_builddir/Optimizer], 1) 261 PHP_ADD_EXTENSION_DEP(opcache, pcre) 262 PHP_SUBST(OPCACHE_SHARED_LIBADD) 263fi 264