diff --git c/plugins/php/common.h w/plugins/php/common.h
index 9bf1c069..061b0b59 100644
--- c/plugins/php/common.h
+++ w/plugins/php/common.h
@@ -3,11 +3,6 @@
 #include "php_main.h"
 #include "php_variables.h"
 
-#if (PHP_MAJOR_VERSION < 7)
-#include "ext/standard/php_smart_str.h"
-#else
-#define UWSGI_PHP7
-#endif
 #include "ext/standard/info.h"
 
 #include "ext/session/php_session.h"
diff --git c/plugins/php/php_plugin.c w/plugins/php/php_plugin.c
index 5cec7805..717d6317 100644
--- c/plugins/php/php_plugin.c
+++ w/plugins/php/php_plugin.c
@@ -4,6 +4,11 @@ extern struct uwsgi_server uwsgi;
 
 static sapi_module_struct uwsgi_sapi_module;
 
+static int uwsgi_php_init(void);
+
+typedef size_t php_strlen_size;
+typedef zend_long php_long_size;
+
 struct uwsgi_php {
 	struct uwsgi_string_list *allowed_docroot;
 	struct uwsgi_string_list *allowed_ext;
@@ -17,7 +22,6 @@ struct uwsgi_php {
 	struct uwsgi_string_list *vars;
 	struct uwsgi_string_list *constants;
 	char *docroot;
-	size_t docroot_len;
 	char *app;
 	char *app_qs;
 	char *fallback;
@@ -32,7 +36,10 @@ struct uwsgi_php {
 	struct uwsgi_string_list *exec_after;
 
 	char *sapi_name;
+
+	int sapi_initialized;
 	HashTable user_config_cache;
+	struct uwsgi_dyn_dict *mountpoint;
 } uphp;
 
 void uwsgi_opt_php_ini(char *opt, char *value, void *foobar) {
@@ -40,6 +47,10 @@ void uwsgi_opt_php_ini(char *opt, char *value, void *foobar) {
         uwsgi_sapi_module.php_ini_ignore = 1;
 }
 
+void uwsgi_opt_early_php(char *opt, char *value, void *foobar) {
+	uwsgi_php_init();
+}
+
 struct uwsgi_option uwsgi_php_options[] = {
 
         {"php-ini", required_argument, 0, "set php.ini path", uwsgi_opt_php_ini, NULL, 0},
@@ -69,15 +80,15 @@ struct uwsgi_option uwsgi_php_options[] = {
         {"php-exec-after", required_argument, 0, "run specified php code after the requested script", uwsgi_opt_add_string_list, &uphp.exec_after, 0},
         {"php-exec-end", required_argument, 0, "run specified php code after the requested script", uwsgi_opt_add_string_list, &uphp.exec_after, 0},
         {"php-sapi-name", required_argument, 0, "hack the sapi name (required for enabling zend opcode cache)", uwsgi_opt_set_str, &uphp.sapi_name, 0},
+
+        {"early-php", no_argument, 0, "initialize an early perl interpreter shared by all loaders", uwsgi_opt_early_php, NULL, UWSGI_OPT_IMMEDIATE},
+        {"early-php-sapi-name", required_argument, 0, "hack the sapi name (required for enabling zend opcode cache)", uwsgi_opt_set_str, &uphp.sapi_name, UWSGI_OPT_IMMEDIATE},
+        {"php-mount", required_argument, 0, "add a php mountpoint", uwsgi_opt_add_dyn_dict, &uphp.mountpoint, 0},
 	UWSGI_END_OF_OPTIONS
 };
 
 
-#ifdef UWSGI_PHP7
-static size_t sapi_uwsgi_ub_write(const char *str, size_t str_length TSRMLS_DC)
-#else
-static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC)
-#endif
+static size_t sapi_uwsgi_ub_write(const char *str, size_t str_length)
 {
 	struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);
 
@@ -89,7 +100,7 @@ static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC)
 	return str_length;
 }
 
-static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
+static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers)
 {
 	sapi_header_struct *h;
 	zend_llist_position pos;
@@ -123,11 +134,7 @@ static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
 	return SAPI_HEADER_SENT_SUCCESSFULLY;
 }
 
-#ifdef UWSGI_PHP7
-static size_t sapi_uwsgi_read_post(char *buffer, size_t count_bytes TSRMLS_DC)
-#else
-static int sapi_uwsgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-#endif
+static size_t sapi_uwsgi_read_post(char *buffer, size_t count_bytes)
 {
 	uint read_bytes = 0;
 	
@@ -151,7 +158,7 @@ static int sapi_uwsgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
 }
 
 
-static char *sapi_uwsgi_read_cookies(TSRMLS_D)
+static char *sapi_uwsgi_read_cookies()
 {
 	uint16_t len = 0;
 	struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);
@@ -164,55 +171,55 @@ static char *sapi_uwsgi_read_cookies(TSRMLS_D)
 	return NULL;
 }
 
-static void sapi_uwsgi_register_variables(zval *track_vars_array TSRMLS_DC)
+static void sapi_uwsgi_register_variables(zval *track_vars_array)
 {
 	int i;
 	struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);
-	php_import_environment_variables(track_vars_array TSRMLS_CC);
+	php_import_environment_variables(track_vars_array);
 
 	if (uphp.server_software) {
 		if (!uphp.server_software_len) uphp.server_software_len = strlen(uphp.server_software);
-		php_register_variable_safe("SERVER_SOFTWARE", uphp.server_software, uphp.server_software_len, track_vars_array TSRMLS_CC);
+		php_register_variable_safe("SERVER_SOFTWARE", uphp.server_software, uphp.server_software_len, track_vars_array);
 	}
 	else {
-		php_register_variable_safe("SERVER_SOFTWARE", "uWSGI", 5, track_vars_array TSRMLS_CC);
+		php_register_variable_safe("SERVER_SOFTWARE", "uWSGI", 5, track_vars_array);
 	}
 
 	for (i = 0; i < wsgi_req->var_cnt; i += 2) {
 		php_register_variable_safe( estrndup(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len),
 			wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len,
-			track_vars_array TSRMLS_CC);
+			track_vars_array);
         }
 
-	php_register_variable_safe("PATH_INFO", wsgi_req->path_info, wsgi_req->path_info_len, track_vars_array TSRMLS_CC);
+	php_register_variable_safe("PATH_INFO", wsgi_req->path_info, wsgi_req->path_info_len, track_vars_array);
 	if (wsgi_req->query_string_len > 0) {
-		php_register_variable_safe("QUERY_STRING", wsgi_req->query_string, wsgi_req->query_string_len, track_vars_array TSRMLS_CC);
+		php_register_variable_safe("QUERY_STRING", wsgi_req->query_string, wsgi_req->query_string_len, track_vars_array);
 	}
 
-	php_register_variable_safe("SCRIPT_NAME", wsgi_req->script_name, wsgi_req->script_name_len, track_vars_array TSRMLS_CC);
-	php_register_variable_safe("SCRIPT_FILENAME", wsgi_req->file, wsgi_req->file_len, track_vars_array TSRMLS_CC);
+	php_register_variable_safe("SCRIPT_NAME", wsgi_req->script_name, wsgi_req->script_name_len, track_vars_array);
+	php_register_variable_safe("SCRIPT_FILENAME", wsgi_req->file, wsgi_req->file_len, track_vars_array);
 
-	php_register_variable_safe("DOCUMENT_ROOT", wsgi_req->document_root, wsgi_req->document_root_len, track_vars_array TSRMLS_CC);
+	php_register_variable_safe("DOCUMENT_ROOT", wsgi_req->document_root, wsgi_req->document_root_len, track_vars_array);
 
 	if (wsgi_req->path_info_len) {
 		char *path_translated = ecalloc(1, wsgi_req->file_len + wsgi_req->path_info_len + 1);
 
 		memcpy(path_translated, wsgi_req->file, wsgi_req->file_len);
 		memcpy(path_translated + wsgi_req->file_len, wsgi_req->path_info, wsgi_req->path_info_len);
-		php_register_variable_safe("PATH_TRANSLATED", path_translated, wsgi_req->file_len + wsgi_req->path_info_len , track_vars_array TSRMLS_CC);
+		php_register_variable_safe("PATH_TRANSLATED", path_translated, wsgi_req->file_len + wsgi_req->path_info_len , track_vars_array);
 	}
 	else {
-		php_register_variable_safe("PATH_TRANSLATED", "", 0, track_vars_array TSRMLS_CC);
+		php_register_variable_safe("PATH_TRANSLATED", "", 0, track_vars_array);
 	}
 
-	php_register_variable_safe("PHP_SELF", wsgi_req->script_name, wsgi_req->script_name_len, track_vars_array TSRMLS_CC);
+	php_register_variable_safe("PHP_SELF", wsgi_req->script_name, wsgi_req->script_name_len, track_vars_array);
 
 	struct uwsgi_string_list *usl = uphp.vars;
 	while(usl) {
 		char *equal = strchr(usl->value, '=');
 		if (equal) {
 			php_register_variable_safe( estrndup(usl->value, equal-usl->value),
-				equal+1, strlen(equal+1), track_vars_array TSRMLS_CC);
+				equal+1, strlen(equal+1), track_vars_array);
 		}
 		usl = usl->next;
 	}
@@ -253,10 +260,7 @@ PHP_MINIT_FUNCTION(uwsgi_php_minit) {
 			char *name = usl->value;
 			char *strval = equal + 1;
 			equal = NULL;
-#ifndef UWSGI_PHP7
-			name_len = name_len + 1;
-#endif
-			zend_register_string_constant(name, name_len, strval, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
+			zend_register_string_constant(name, name_len, strval, CONST_CS | CONST_PERSISTENT, module_number);
 		}
 		usl = usl->next;
 	}
@@ -264,11 +268,7 @@ PHP_MINIT_FUNCTION(uwsgi_php_minit) {
 }
 
 PHP_FUNCTION(uwsgi_version) {
-#ifdef UWSGI_PHP7
 	RETURN_STRING(UWSGI_VERSION);
-#else
-	RETURN_STRING(UWSGI_VERSION, 1);
-#endif
 }
 
 PHP_FUNCTION(uwsgi_worker_id) {
@@ -285,11 +285,11 @@ PHP_FUNCTION(uwsgi_masterpid) {
 PHP_FUNCTION(uwsgi_cache_exists) {
 
         char *key = NULL;
-        int keylen = 0;
+        php_strlen_size keylen = 0;
         char *cache = NULL;
-        int cachelen = 0;
+        php_strlen_size cachelen = 0;
 
-        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
+        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
                 RETURN_NULL();
         }
 
@@ -303,9 +303,9 @@ PHP_FUNCTION(uwsgi_cache_exists) {
 PHP_FUNCTION(uwsgi_cache_clear) {
 
         char *cache = NULL;
-        int cachelen = 0;
+        php_strlen_size cachelen = 0;
 
-        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &cache, &cachelen) == FAILURE) {
+        if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &cache, &cachelen) == FAILURE) {
                 RETURN_NULL();
         }
 
@@ -318,13 +318,13 @@ PHP_FUNCTION(uwsgi_cache_clear) {
 
 
 PHP_FUNCTION(uwsgi_cache_del) {
-	
+
 	char *key = NULL;
-        int keylen = 0;
+	php_strlen_size keylen = 0;
 	char *cache = NULL;
-	int cachelen = 0;
+	php_strlen_size cachelen = 0;
 
-        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
+        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
                 RETURN_NULL();
         }
 
@@ -338,15 +338,15 @@ PHP_FUNCTION(uwsgi_cache_del) {
 PHP_FUNCTION(uwsgi_cache_get) {
 
 	char *key = NULL;
-	int keylen = 0;
+	php_strlen_size keylen = 0;
 	char *cache = NULL;
-	int cachelen = 0;
+	php_strlen_size cachelen = 0;
 	uint64_t valsize;
 
 	if (!uwsgi.caches)
 		RETURN_NULL();
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
                 RETURN_NULL();
         }
 
@@ -354,28 +354,24 @@ PHP_FUNCTION(uwsgi_cache_get) {
 	if (value) {
 		char *ret = estrndup(value, valsize);
 		free(value);
-#ifdef UWSGI_PHP7
 		RETURN_STRING(ret);
-#else
-		RETURN_STRING(ret, 0);
-#endif
 	}
 	RETURN_NULL();
 }
 
 PHP_FUNCTION(uwsgi_cache_set) {
 	char *key = NULL;	
-	int keylen;
+	php_strlen_size keylen = 0;
 	char *value = NULL;
-	int vallen;
-	uint64_t expires = 0;
+	php_strlen_size vallen = 0;
+	php_long_size expires = 0;
 	char *cache = NULL;
-	int cachelen = 0;
+	php_strlen_size cachelen = 0;
 
 	if (!uwsgi.caches)
 		RETURN_NULL();
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", &key, &keylen, &value, &vallen, &expires, &cache, &cachelen) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", &key, &keylen, &value, &vallen, &expires, &cache, &cachelen) == FAILURE) {
                 RETURN_NULL();
         }
 
@@ -388,17 +384,17 @@ PHP_FUNCTION(uwsgi_cache_set) {
 
 PHP_FUNCTION(uwsgi_cache_update) {
         char *key = NULL;
-        int keylen;
+        php_strlen_size keylen = 0;
         char *value = NULL;
-        int vallen;
-        uint64_t expires = 0;
+        php_strlen_size vallen = 0;
+        php_long_size expires = 0;
         char *cache = NULL;
-        int cachelen = 0;
+        php_strlen_size cachelen = 0;
 
         if (!uwsgi.caches)
                 RETURN_NULL();
 
-        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", &key, &keylen, &value, &vallen, &expires, &cache, &cachelen) == FAILURE) {
+        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", &key, &keylen, &value, &vallen, &expires, &cache, &cachelen) == FAILURE) {
                 RETURN_NULL();
         }
 
@@ -423,7 +419,7 @@ PHP_FUNCTION(uwsgi_rpc) {
         uint16_t argvs[256];
 	uint64_t size = 0;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &varargs, &num_args) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &varargs, &num_args) == FAILURE) {
 		RETURN_NULL();
 	}
 
@@ -462,11 +458,7 @@ PHP_FUNCTION(uwsgi_rpc) {
 		// here we do not free varargs for performance reasons
 		char *ret = estrndup(response, size);
 		free(response);
-#ifdef UWSGI_PHP7
 		RETURN_STRING(ret);
-#else
-		RETURN_STRING(ret, 0);
-#endif
         }
 
 clear:
@@ -481,7 +473,7 @@ PHP_FUNCTION(uwsgi_setprocname) {
 	char *name;
 	int name_len;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
 		RETURN_NULL();
 	}
 
@@ -495,7 +487,7 @@ PHP_FUNCTION(uwsgi_signal) {
 	long long_signum;
 	uint8_t signum = 0;
 
-        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &long_signum) == FAILURE) {
+        if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &long_signum) == FAILURE) {
                 RETURN_NULL();
         }
 
@@ -629,10 +621,12 @@ static int php_uwsgi_startup(sapi_module_struct *sapi_module)
 	}
 }
 
-#if ((PHP_MAJOR_VERSION >= 7) && (PHP_MINOR_VERSION >= 1))
+#if (PHP_MAJOR_VERSION >= 8)
+static void sapi_uwsgi_log_message(const char *message, int syslog_type_int) {
+#elif ((PHP_MAJOR_VERSION == 7) && (PHP_MINOR_VERSION >= 1))
 static void sapi_uwsgi_log_message(char *message, int syslog_type_int) {
 #else
-static void sapi_uwsgi_log_message(char *message TSRMLS_DC) {
+static void sapi_uwsgi_log_message(char *message) {
 #endif
 	uwsgi_log("%s\n", message);
 }
@@ -668,16 +662,32 @@ static sapi_module_struct uwsgi_sapi_module = {
 	STANDARD_SAPI_MODULE_PROPERTIES
 };
 
-int uwsgi_php_init(void) {
+static void uwsgi_php_init_mount(struct uwsgi_dyn_dict *mount_dict) {
+	struct uwsgi_dyn_dict *udd = mount_dict;
+	while (udd) {
+		char *orig_dest = udd->value;
+		udd->value = uwsgi_expand_path(udd->value, udd->vallen, NULL);
+		udd->vallen = strlen(udd->value);
+		if (!udd->value) {
+			uwsgi_log("Unable to expand php mountpoint to %s\n", orig_dest);
+			exit(1);
+		}
+		udd = udd->next;
+	}
+}
+
+static int uwsgi_php_init(void) {
 
 	struct uwsgi_string_list *pset = uphp.set;
 	struct uwsgi_string_list *append_config = uphp.append_config;
 
+	if (!uphp.sapi_initialized) {
 #ifdef ZTS
-        tsrm_startup(1, 1, 0, NULL);
+        	tsrm_startup(1, 1, 0, NULL);
 #endif
-
-	sapi_startup(&uwsgi_sapi_module);
+		sapi_startup(&uwsgi_sapi_module);
+		uphp.sapi_initialized = 1;
+	}
 
 	// applying custom options
 	while(append_config) {
@@ -705,13 +715,14 @@ int uwsgi_php_init(void) {
 			uwsgi_log("unable to set php docroot to %s\n", orig_docroot);
 			exit(1);
 		}
-		uwsgi_log("PHP document root set to %s\n", uphp.docroot);
-		uphp.docroot_len = strlen(uphp.docroot);
 	}
 
+	uwsgi_php_init_mount(uphp.mountpoint);
+
 	if (uphp.sapi_name) {
 		uwsgi_sapi_module.name = uphp.sapi_name;
 	}
+
 	uwsgi_sapi_module.startup(&uwsgi_sapi_module);
 	uwsgi_log("PHP %s initialized\n", PHP_VERSION);
 
@@ -776,6 +787,33 @@ int uwsgi_php_walk(struct wsgi_request *wsgi_req, char *full_path, char *docroot
 
 }
 
+static char *uwsgi_php_get_mount(char *path_info, uint16_t path_info_len, struct uwsgi_dyn_dict *mount_dict, int *discard_base) {
+	int best_found = 0;
+	struct uwsgi_dyn_dict *udd = mount_dict, *chosen = NULL;
+
+	while (udd) {
+		if (mount_dict->vallen) {
+			if (!uwsgi_starts_with(path_info, path_info_len, udd->key, udd->keylen)) {
+				if (udd->keylen > best_found) {
+					best_found = udd->keylen;
+					chosen = udd;
+				}
+			}
+		}
+		udd = udd->next;
+	}
+
+	if (chosen) {
+		*discard_base = chosen->keylen;
+		if (chosen->key[chosen->keylen-1] == '/') {
+			*discard_base = *discard_base - 1;
+		}
+		return chosen->value;
+	} else {
+		return NULL;
+	}
+}
+
 
 int uwsgi_php_request(struct wsgi_request *wsgi_req) {
 
@@ -788,10 +826,6 @@ int uwsgi_php_request(struct wsgi_request *wsgi_req) {
 
 	zend_file_handle file_handle;
 
-#ifdef ZTS
-	TSRMLS_FETCH();
-#endif
-
 	SG(server_context) = (void *) wsgi_req;
 
 	if (uwsgi_parse_vars(wsgi_req)) {
@@ -801,7 +835,15 @@ int uwsgi_php_request(struct wsgi_request *wsgi_req) {
 	char *orig_path_info = wsgi_req->path_info;
 	uint16_t orig_path_info_len = wsgi_req->path_info_len;
 
-	if (uphp.docroot) {
+	int discard_base = 0;
+
+	char *mount_docroot = uwsgi_php_get_mount(wsgi_req->path_info, wsgi_req->path_info_len, uphp.mountpoint, &discard_base);
+
+	if (mount_docroot) {
+		wsgi_req->document_root = mount_docroot;
+		wsgi_req->path_info = wsgi_req->path_info+discard_base;
+		wsgi_req->path_info_len = wsgi_req->path_info_len-discard_base;
+	} else if (uphp.docroot) {
 		wsgi_req->document_root = uphp.docroot;
 	}
 	// fallback to cwd
@@ -833,7 +875,8 @@ int uwsgi_php_request(struct wsgi_request *wsgi_req) {
                 }
 #endif
 
-		strcpy(real_filename, uphp.app);	
+		strncpy(real_filename, uphp.app, PATH_MAX);
+		real_filename[PATH_MAX-1] = '\0';
 		if (wsgi_req->path_info_len == 1 && wsgi_req->path_info[0] == '/') {
 			goto appready;
 		}
@@ -926,7 +969,6 @@ oldstyle:
 	free(filename);
 	real_filename_len = strlen(real_filename);
 
-	// first check for valid doc roots
 	if (uphp.allowed_docroot) {
 		struct uwsgi_string_list *usl = uphp.allowed_docroot;
 		while(usl) {
@@ -939,16 +981,6 @@ oldstyle:
 		uwsgi_log("PHP security error: %s is not under an allowed docroot\n", real_filename);
 		return -1;
 	}
-	// then for default docroot (if any)
-	else if (uphp.docroot)
-	{
-		if (!uwsgi_starts_with(real_filename, real_filename_len, uphp.docroot, uphp.docroot_len)) {
-			goto secure;
-		}
-		uwsgi_403(wsgi_req);
-		uwsgi_log("PHP security error: %s is not under the default docroot\n", real_filename);
-		return -1;
-	}
 
 secure:
 
@@ -1065,7 +1097,7 @@ secure3:
         file_handle.type = ZEND_HANDLE_FILENAME;
         file_handle.filename = real_filename;
 
-        if (php_request_startup(TSRMLS_C) == FAILURE) {
+        if (php_request_startup() == FAILURE) {
 		uwsgi_500(wsgi_req);
                 return -1;
         }
@@ -1073,13 +1105,13 @@ secure3:
 	struct uwsgi_string_list *usl=NULL;
 
 	uwsgi_foreach(usl, uphp.exec_before) {
-		if (zend_eval_string_ex(usl->value, NULL, "uWSGI php exec before", 1 TSRMLS_CC) == FAILURE) goto end;
+		if (zend_eval_string_ex(usl->value, NULL, "uWSGI php exec before", 1) == FAILURE) goto end;
 	}
 
-        php_execute_script(&file_handle TSRMLS_CC);
+        php_execute_script(&file_handle);
 
 	uwsgi_foreach(usl, uphp.exec_after) {
-		if (zend_eval_string_ex(usl->value, NULL, "uWSGI php exec after", 1 TSRMLS_CC) == FAILURE) goto end;
+		if (zend_eval_string_ex(usl->value, NULL, "uWSGI php exec after", 1) == FAILURE) goto end;
 	}
 
 end:
diff --git c/plugins/php/session.c w/plugins/php/session.c
index 2312b6b9..cce06985 100644
--- c/plugins/php/session.c
+++ w/plugins/php/session.c
@@ -12,34 +12,20 @@ PS_CLOSE_FUNC(uwsgi) {
 PS_READ_FUNC(uwsgi) {
 	char *cache = PS_GET_MOD_DATA();
 	uint64_t valsize = 0;
-#ifdef UWSGI_PHP7
 	char *value = uwsgi_cache_magic_get(key->val, key->len , &valsize, NULL, cache);
-#else
-	char *value = uwsgi_cache_magic_get((char *)key, strlen((char *)key), &valsize, NULL, cache);
-#endif
-        if (!value) return FAILURE;
-#ifdef UWSGI_PHP7
+	if (!value) {
+		*val = STR_EMPTY_ALLOC();
+		return SUCCESS;
+	}
 	*val = zend_string_init(value, valsize, 0);
-#else
-	char *new_val = emalloc(valsize);
-	memcpy(new_val, value, valsize);
-	free(value);
-	*val = new_val;
-	*vallen = valsize;
-#endif
 	return SUCCESS;
 	
 }
 
 PS_WRITE_FUNC(uwsgi) {
 	char *cache = PS_GET_MOD_DATA();
-#ifdef UWSGI_PHP7
 	if (val->len == 0) return SUCCESS;
 	if (!uwsgi_cache_magic_set(key->val, key->len, val->val, val->len, 0, UWSGI_CACHE_FLAG_UPDATE, cache)) {
-#else
-	if (vallen == 0) return SUCCESS;
-	if (!uwsgi_cache_magic_set((char *)key, strlen(key), (char *)val, vallen, 0, UWSGI_CACHE_FLAG_UPDATE, cache)) {
-#endif
 		return SUCCESS;	
 	}
 	return FAILURE;
@@ -47,11 +33,10 @@ PS_WRITE_FUNC(uwsgi) {
 
 PS_DESTROY_FUNC(uwsgi) {
 	char *cache = PS_GET_MOD_DATA();
-#ifdef UWSGI_PHP7
+	if (!uwsgi_cache_magic_exists(key->val, key->len, cache))
+		return SUCCESS;
+
 	if (!uwsgi_cache_magic_del(key->val, key->len, cache)) {
-#else
-	if (!uwsgi_cache_magic_del((char *)key, strlen(key), cache)) {
-#endif
 		return SUCCESS;
 	}
 	return FAILURE;
diff --git c/plugins/php/uwsgiplugin.py w/plugins/php/uwsgiplugin.py
index d930c44e..8657eb70 100644
--- c/plugins/php/uwsgiplugin.py
+++ w/plugins/php/uwsgiplugin.py
@@ -1,6 +1,6 @@
 import os
 
-NAME='php'
+NAME = 'php'
 
 ld_run_path = None
 PHPPATH = 'php-config'