--- xcache-1.2.2/xcache.c	2007-12-28 17:00:00.000000000 +0100
+++ xcache-1.2.2.rayshark.1/xcache.c	2009-07-30 20:27:11.000000000 +0200
@@ -652,7 +652,7 @@
 	xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size TSRMLS_CC);
 }
 /* }}} */
-static int xc_stat(const char *filename, const char *include_path, struct stat *pbuf TSRMLS_DC) /* {{{ */
+static int xc_stat(const char *filename, const char *include_path, char *full_path, struct stat *pbuf TSRMLS_DC) /* {{{ */
 {
 	char filepath[MAXPATHLEN];
 	char *paths, *path;
@@ -660,14 +660,37 @@
 	int size = strlen(include_path) + 1;
 	char tokens[] = { DEFAULT_DIR_SEPARATOR, '\0' };
 
-	paths = (char *)do_alloca(size);
-	memcpy(paths, include_path, size);
+	if (zend_is_executing(TSRMLS_C)) {
+		char *exec_fname = zend_get_executed_filename(TSRMLS_C);
+		int exec_fname_length = strlen(exec_fname);
+		int path_length = strlen(include_path);
+
+		while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length]));
+		if ((exec_fname && exec_fname[0] == '[')
+			|| exec_fname_length<=0) {
+			/* [no active file] or no path */
+			paths = (char *)do_alloca(size);
+			memcpy(paths, include_path, size);
+		} else {
+			paths = (char *) do_alloca(exec_fname_length + path_length +1 +1);
+			memcpy(paths, include_path, path_length);
+			paths[path_length] = DEFAULT_DIR_SEPARATOR;
+			memcpy(paths+path_length+1, exec_fname, exec_fname_length);
+			paths[path_length + exec_fname_length +1] = '\0';
+		}
+	} else {
+		paths = (char *)do_alloca(size);
+		memcpy(paths, include_path, size);
+	}
 
 	for (path = php_strtok_r(paths, tokens, &tokbuf); path; path = php_strtok_r(NULL, tokens, &tokbuf)) {
 		if (snprintf(filepath, sizeof(filepath), "%s/%s", path, filename) >= MAXPATHLEN - 1) {
 			continue;
 		}
 		if (VCWD_STAT(filepath, pbuf) == 0) {
+			if (full_path) {
+				memcpy(full_path, filepath, strlen(filepath) + 1);
+			}
 			free_alloca(paths);
 			return 0;
 		}
@@ -719,6 +742,8 @@
 	xc_entry_data_php_t *php;
 	char *ptr;
 	time_t delta;
+	char real_name_buffer[MAXPATHLEN];
+	int real_name = 0;
 
 	if (!filename || !SG(request_info).path_translated) {
 		return 0;
@@ -762,9 +787,10 @@
 not_relative_path:
 
 		/* use include_path */
-		if (xc_stat(filename, PG(include_path), pbuf TSRMLS_CC) != 0) {   
+		if (xc_stat(filename, PG(include_path), real_name_buffer, pbuf TSRMLS_CC) != 0) {   
 			return 0;
 		}
+		real_name = 1;
 
 		/* fall */
 
@@ -795,7 +821,12 @@
 #endif
 	{
 		/* hash on filename, let's expand it to real path */
-		filename = expand_filepath(filename, opened_path_buffer TSRMLS_CC);
+		if (!real_name) {
+			filename = expand_filepath(filename, opened_path_buffer TSRMLS_CC);
+		} else {
+			filename = expand_filepath(real_name_buffer, opened_path_buffer TSRMLS_CC);
+		}
+
 		if (filename == NULL) {
 			return 0;
 		}
