diff --git a/plugins/php/common.h b/plugins/php/common.h new file mode 100644 index 00000000..8c1ed139 --- /dev/null +++ b/plugins/php/common.h @@ -0,0 +1,12 @@ +#include "php.h" +#include "SAPI.h" +#include "php_main.h" +#include "php_variables.h" + +#include "ext/standard/php_smart_str.h" +#include "ext/standard/info.h" + +#include "ext/session/php_session.h" + +#include + diff --git a/plugins/php/php_plugin.c b/plugins/php/php_plugin.c index 93169944..dbe7acdf 100644 --- a/plugins/php/php_plugin.c +++ b/plugins/php/php_plugin.c @@ -1,12 +1,4 @@ -#include "php.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_variables.h" - -#include "ext/standard/php_smart_str.h" -#include "ext/standard/info.h" - -#include "../../uwsgi.h" +#include "common.h" extern struct uwsgi_server uwsgi; @@ -233,8 +225,9 @@ void uwsgi_php_set(char *opt) { uwsgi_sapi_module.ini_entries[uphp.ini_size] = 0; } -// future implementation... +extern ps_module ps_mod_uwsgi; PHP_MINIT_FUNCTION(uwsgi_php_minit) { + php_session_register_module(&ps_mod_uwsgi); return SUCCESS; } @@ -341,7 +334,7 @@ PHP_FUNCTION(uwsgi_cache_set) { RETURN_NULL(); } - if (uwsgi_cache_magic_set(key, keylen, value, vallen, expires, 0, cache)) { + if (!uwsgi_cache_magic_set(key, keylen, value, vallen, expires, 0, cache)) { RETURN_TRUE; } RETURN_NULL(); @@ -363,7 +356,7 @@ PHP_FUNCTION(uwsgi_cache_update) { RETURN_NULL(); } - if (uwsgi_cache_magic_set(key, keylen, value, vallen, expires, UWSGI_CACHE_FLAG_UPDATE, cache)) { + if (!uwsgi_cache_magic_set(key, keylen, value, vallen, expires, UWSGI_CACHE_FLAG_UPDATE, cache)) { RETURN_TRUE; } RETURN_NULL(); diff --git a/plugins/php/session.c b/plugins/php/session.c new file mode 100644 index 00000000..40f9ef73 --- /dev/null +++ b/plugins/php/session.c @@ -0,0 +1,50 @@ +#include "common.h" + +PS_OPEN_FUNC(uwsgi) { + PS_SET_MOD_DATA((char *)save_path); + return SUCCESS; +} + +PS_CLOSE_FUNC(uwsgi) { + return SUCCESS; +} + +PS_READ_FUNC(uwsgi) { + char *cache = PS_GET_MOD_DATA(); + uint64_t valsize = 0; + char *value = uwsgi_cache_magic_get((char *)key, strlen(key), &valsize, NULL, cache); + if (!value) return FAILURE; + char *new_val = emalloc(valsize); + memcpy(new_val, value, valsize); + free(value); + *val = new_val; + *vallen = valsize; + return SUCCESS; + +} + +PS_WRITE_FUNC(uwsgi) { + char *cache = PS_GET_MOD_DATA(); + if (vallen == 0) return SUCCESS; + if (!uwsgi_cache_magic_set((char *)key, strlen(key), (char *)val, vallen, 0, UWSGI_CACHE_FLAG_UPDATE, cache)) { + return SUCCESS; + } + return FAILURE; +} + +PS_DESTROY_FUNC(uwsgi) { + char *cache = PS_GET_MOD_DATA(); + if (!uwsgi_cache_magic_del((char *)key, strlen(key), cache)) { + return SUCCESS; + } + return FAILURE; +} + +PS_GC_FUNC(uwsgi) { + return SUCCESS; +} + +ps_module ps_mod_uwsgi = { + PS_MOD(uwsgi) +}; + diff --git a/plugins/php/uwsgiplugin.py b/plugins/php/uwsgiplugin.py index 4142aeae..e7ce425f 100644 --- a/plugins/php/uwsgiplugin.py +++ b/plugins/php/uwsgiplugin.py @@ -25,4 +25,4 @@ phplibdir = os.environ.get('UWSGICONFIG_PHPLIBDIR') if phplibdir: LIBS.append('-Wl,-rpath=%s' % phplibdir) -GCC_LIST = ['php_plugin'] +GCC_LIST = ['php_plugin', 'session']