Created
October 21, 2013 09:19
-
-
Save laruence/7080980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ZendAccelerator.c b/ZendAccelerator.c | |
index 72b5a1b..002a71a 100644 | |
--- a/ZendAccelerator.c | |
+++ b/ZendAccelerator.c | |
@@ -37,6 +37,9 @@ | |
#include "zend_API.h" | |
#include "zend_ini.h" | |
#include "TSRM/tsrm_virtual_cwd.h" | |
+#ifdef HAVE_PHAR_HEADER | |
+#include "ext/phar/php_phar.h" | |
+#endif | |
#include "zend_accelerator_util_funcs.h" | |
#include "zend_accelerator_hash.h" | |
@@ -144,6 +147,24 @@ static inline int is_cacheable_stream_path(const char *filename) | |
memcmp(filename, "phar://", sizeof("phar://") - 1) == 0; | |
} | |
+#ifdef HAVE_PHAR_HEADER | |
+static inline int is_phar_relative_alias_path(const char *filename, char **alias, int *alias_len) | |
+{ | |
+ if (memcmp(filename, "phar://", sizeof("phar://") - 1) == 0 | |
+ && filename[sizeof("phar://") - 1] != '\0' && filename[sizeof("phar://") - 1] != '/') { | |
+ char *slash; | |
+ *alias = filename + sizeof("phar://") - 1; | |
+ slash = strstr(*alias, "/"); | |
+ if (slash) { | |
+ *alias_len = slash - *alias; | |
+ return 1; | |
+ } | |
+ } | |
+ return 0; | |
+} | |
+#endif | |
+ | |
+ | |
/* O+ overrides PHP chdir() function and remembers the current working directory | |
* in ZCG(cwd) and ZCG(cwd_len). Later accel_getcwd() can use stored value and | |
* avoid getcwd() call. | |
@@ -1035,7 +1056,30 @@ char *accel_make_persistent_key_ex(zend_file_handle *file_handle, int path_lengt | |
ZCG(key_len) = 0; | |
return NULL; | |
} | |
+#ifdef HAVE_PHAR_HEADER | |
+ else { | |
+ char *alias; | |
+ int alias_len; | |
+ if (is_phar_relative_alias_path(file_handle->filename, &alias, &alias_len)) { | |
+ char *phar_path; | |
+ int phar_path_len; | |
+ if (phar_resolve_alias(alias, alias_len, &phar_path, &phar_path_len TSRMLS_CC) == SUCCESS) { | |
+ int filename_len = strlen(file_handle->filename); | |
+ memcpy(ZCG(key), "phar://", sizeof("phar://") -1); | |
+ memcpy(ZCG(key) + sizeof("phar://") - 1, phar_path, phar_path_len); | |
+ memcpy(ZCG(key) + sizeof("phar://") - 1 + phar_path_len, | |
+ alias + alias_len, filename_len - alias_len - sizeof("phar://") + 2); | |
+ key_length = filename_len + (phar_path_len - alias_len); | |
+ } else { | |
+ memcpy(ZCG(key), file_handle->filename, key_length + 1); | |
+ } | |
+ } else { | |
+ memcpy(ZCG(key), file_handle->filename, key_length + 1); | |
+ } | |
+ } | |
+#else | |
memcpy(ZCG(key), file_handle->filename, key_length + 1); | |
+#endif | |
} | |
*key_len = ZCG(key_len) = key_length; | |
diff --git a/config.m4 b/config.m4 | |
index 60edeed..2ac7da4 100644 | |
--- a/config.m4 | |
+++ b/config.m4 | |
@@ -362,6 +362,10 @@ AC_TRY_RUN([ | |
if test "$flock_type" == "unknown"; then | |
AC_MSG_ERROR([Don't know how to define struct flock on this system[,] set --enable-opcache=no]) | |
fi | |
+ | |
+if test -r $phpincludedir"/ext/phar/php_phar.h"; then | |
+ AC_DEFINE([HAVE_PHAR_HEADER], [], [phar header file exists]) | |
+fi | |
PHP_NEW_EXTENSION(opcache, | |
ZendAccelerator.c \ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment