diff --git a/src/mod/languages/mod_php/Makefile b/src/mod/languages/mod_php/Makefile index b6607a4cc4..3a9b9723b7 100644 --- a/src/mod/languages/mod_php/Makefile +++ b/src/mod/languages/mod_php/Makefile @@ -1,29 +1,33 @@ -CFLAGS += -I$(PREFIX)/include/php/TSRM -I$(PREFIX)/include/php/main/ -I$(PREFIX)/include/php/Zend/ -I$(PREFIX)/include/php/ +#Usage: /usr/local/freeswitch/bin/php-config [--prefix|--includes|--ldflags|--libs|--extension-dir|--include-dir|--php-binary|--version] +PCFG=$(PREFIX)/bin/php-config + +LCFLAGS=-fPIC -DZTS -DPTHREADS +CFLAGS += `$(PCFG) --includes` PHPMOD=freeswitch -LDFLAGS += -lphp4 +LDFLAGS += `$(PCFG) --ldflags` -lcrypt -lcrypt -lresolv -lm -ldl -lnsl -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lphp5 all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PHPMOD).$(DYNAMIC_LIB_EXTEN) depends: - MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install php-4.4.4.tar.gz --prefix=$(PREFIX) --enable-embed + MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install php-5.1.6.tar.gz --prefix=$(PREFIX) --enable-embed=static --enable-static --with-pic %.o: %.c - $(CC) -fPIC $(CFLAGS) -c $< -o $@ + $(CC) $(LCFLAGS) $(CFLAGS) -c $< -o $@ reswig: rm -f switch_swig_wrap.c config.m4 CREDITS *$(PHPMOD)* swig -lswitch_swig.i -ignoremissing -DMULTIPLICITY -php -module $(PHPMOD) switch_swig.c patch -p0 -i fix.diff -switch_swig_wrap.o: switch_swig_wrap.c - $(CC) -w $(CFLAGS) -c $< -o $@ +switch_swig_wrap.o: switch_swig_wrap.c Makefile + $(CC) $(LCFLAGS) -w $(CFLAGS) -c $< -o $@ -$(PHPMOD).$(DYNAMIC_LIB_EXTEN): $(MODNAME).$(DYNAMIC_LIB_EXTEN) switch_swig_wrap.o switch_swig.o +$(PHPMOD).$(DYNAMIC_LIB_EXTEN): $(MODNAME).$(DYNAMIC_LIB_EXTEN) switch_swig_wrap.o switch_swig.o Makefile $(CC) $(SOLINK) -o php_$(PHPMOD).$(DYNAMIC_LIB_EXTEN) switch_swig_wrap.o switch_swig.o $(LDFLAGS) -$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(MODNAME).o $(OBJS) - $(CC) -fPIC $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(MODNAME).o $(OBJS) $(LDFLAGS) +$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(MODNAME).o $(OBJS) Makefile + $(CC) $(LCFLAGS) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(MODNAME).o $(OBJS) $(LDFLAGS) clean: rm -fr *.$(DYNAMIC_LIB_EXTEN) *.o *~ diff --git a/src/mod/languages/mod_php/mod_php.c b/src/mod/languages/mod_php/mod_php.c index 1f12ca64af..c94727b307 100644 --- a/src/mod/languages/mod_php/mod_php.c +++ b/src/mod/languages/mod_php/mod_php.c @@ -30,7 +30,15 @@ * mod_php.c -- PHP Module * */ -#include + +#ifndef _REENTRANT +#define _REENTRANT +#endif + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include "php.h" #include "php_variables.h" #include "ext/standard/info.h" @@ -42,6 +50,8 @@ #include "TSRM.h" #include "ext/standard/php_standard.h" +#include + const char modname[] = "mod_php"; static int php_freeswitch_startup(sapi_module_struct *sapi_module) @@ -239,8 +249,8 @@ static void freeswitch_request_ctor(switch_php_obj_t *request_context TSRMLS_DC) SG(request_info).argc = request_context->argc; SG(request_info).argv = request_context->argv; - SG(request_info).path_translated = estrdup(request_context->argv[0]); + } static void freeswitch_request_dtor(switch_php_obj_t *request_context TSRMLS_DC) @@ -276,10 +286,10 @@ static void php_function(switch_core_session_t *session, char *data) uint32_t len = strlen((char *) data) + ulen + 2; char *mydata = switch_core_session_alloc(session, len); - snprintf(mydata, len, "-q %s %s", data, uuid); - TSRMLS_FETCH(); + snprintf(mydata, len, "%s %s", data, uuid); + request_context = (switch_php_obj_t *) switch_core_session_alloc(session, sizeof(*request_context)); request_context->session = session; @@ -333,6 +343,15 @@ static switch_loadable_module_interface_t php_module_interface = { SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename) { + + php_core_globals *core_globals; + + tsrm_startup(128, 1, 0, NULL); + core_globals = ts_resource(core_globals_id); + + sapi_startup(&fs_sapi_module); + fs_sapi_module.startup(&fs_sapi_module); + /* connect my internal structure to the blank pointer passed to me */ *module_interface = &php_module_interface;