]> granicus.if.org Git - php/commitdiff
Fixed compatibility with ext/phar
authorDmitry Stogov <dmitry@zend.com>
Sat, 16 Mar 2013 12:08:11 +0000 (16:08 +0400)
committerDmitry Stogov <dmitry@zend.com>
Sat, 16 Mar 2013 12:08:11 +0000 (16:08 +0400)
ext/opcache/ZendAccelerator.c
ext/opcache/zend_accelerator_module.c

index 17eac09caf8e7c5b5c8a1f676910cce6aab80b9c..daf80cea29f671657d8ef5a82a04514a87af289f 100644 (file)
@@ -1221,7 +1221,9 @@ static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_han
        }
 
 #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
-       if (file_handle->type == ZEND_HANDLE_STREAM) {
+       if (file_handle->type == ZEND_HANDLE_STREAM &&
+           (!strstr(file_handle->filename, ".phar") ||
+            strstr(file_handle->filename, "://"))) {
                char *buf;
                size_t size;
 
index e55884aba1e8994033cd411af392340ad000af64..11dd7d3220c69ca3d96a18d4f6f9dce4e1643bc0 100644 (file)
 #define MAX_ACCEL_FILES 100000
 #define TOKENTOSTR(X) #X
 
+static void (*orig_file_exists)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
+static void (*orig_is_file)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
+static void (*orig_is_readable)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
+
 /* User functions */
 static ZEND_FUNCTION(opcache_reset);
 
@@ -280,50 +284,44 @@ static int filename_is_in_cache(char *filename, int filename_len TSRMLS_DC)
        return 0;
 }
 
-static void accel_file_in_cache(int type, INTERNAL_FUNCTION_PARAMETERS)
+static int accel_file_in_cache(INTERNAL_FUNCTION_PARAMETERS)
 {
-       char *filename;
-       int filename_len;
-#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
        zval **zfilename;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zfilename) == FAILURE) {
-               WRONG_PARAM_COUNT;
-       }
-       convert_to_string_ex(zfilename);
-       filename = Z_STRVAL_PP(zfilename);
-       filename_len = Z_STRLEN_PP(zfilename);
-#elif ZEND_EXTENSION_API_NO == PHP_5_3_X_API_NO
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
-               return;
-       }
-#else
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
-               return;
-       }
-#endif
-       if (filename_len > 0) {
-               if (filename_is_in_cache(filename, filename_len TSRMLS_CC)) {
-                       RETURN_TRUE;
-               }
+       if (ZEND_NUM_ARGS() != 1 ||
+           zend_get_parameters_array_ex(1, &zfilename) == FAILURE ||
+           Z_TYPE_PP(zfilename) != IS_STRING ||
+           Z_STRLEN_PP(zfilename) == 0) {
+               return 0;
        }
-
-       php_stat(filename, filename_len, type, return_value TSRMLS_CC);
+       return filename_is_in_cache(Z_STRVAL_PP(zfilename), Z_STRLEN_PP(zfilename) TSRMLS_CC);
 }
 
 static void accel_file_exists(INTERNAL_FUNCTION_PARAMETERS)
 {
-       accel_file_in_cache(FS_EXISTS, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       if (accel_file_in_cache(INTERNAL_FUNCTION_PARAM_PASSTHRU)) {
+               RETURN_TRUE;
+       } else {
+               orig_file_exists(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       }
 }
 
 static void accel_is_file(INTERNAL_FUNCTION_PARAMETERS)
 {
-       accel_file_in_cache(FS_IS_FILE, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       if (accel_file_in_cache(INTERNAL_FUNCTION_PARAM_PASSTHRU)) {
+               RETURN_TRUE;
+       } else {
+               orig_is_file(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       }
 }
 
 static void accel_is_readable(INTERNAL_FUNCTION_PARAMETERS)
 {
-       accel_file_in_cache(FS_IS_R, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       if (accel_file_in_cache(INTERNAL_FUNCTION_PARAM_PASSTHRU)) {
+               RETURN_TRUE;
+       } else {
+               orig_is_readable(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       }
 }
 
 static ZEND_MINIT_FUNCTION(zend_accelerator)
@@ -346,12 +344,15 @@ void zend_accel_override_file_functions(TSRMLS_D)
        if (ZCG(enabled) && accel_startup_ok && ZCG(accel_directives).file_override_enabled) {
                /* override file_exists */
                if (zend_hash_find(CG(function_table), "file_exists", sizeof("file_exists"), (void **)&old_function) == SUCCESS) {
+                       orig_file_exists = old_function->internal_function.handler;
                        old_function->internal_function.handler = accel_file_exists;
                }
                if (zend_hash_find(CG(function_table), "is_file", sizeof("is_file"), (void **)&old_function) == SUCCESS) {
+                       orig_is_file = old_function->internal_function.handler;
                        old_function->internal_function.handler = accel_is_file;
                }
                if (zend_hash_find(CG(function_table), "is_readable", sizeof("is_readable"), (void **)&old_function) == SUCCESS) {
+                       orig_is_readable = old_function->internal_function.handler;
                        old_function->internal_function.handler = accel_is_readable;
                }
        }