void PHPModule::Stop() { PHPModule::instance_ = NULL; KObjectRef global = this->host->GetGlobalObject(); Script::GetInstance()->RemoveScriptEvaluator(this->binding); global->Set("PHP", Value::Undefined); this->binding->Set("evaluate", Value::Undefined); this->binding = 0; PHPModule::instance_ = 0; php_embed_shutdown(TSRMLS_C); }
static void __attribute__((destructor)) fini() { php_embed_shutdown(TSRMLS_C); }
samphp::~samphp() { php_embed_shutdown(TSRMLS_CC); }
/** * Load a PHP script then run the function corresponding to the service by * passing the conf, inputs and outputs parameters by reference. * * @param main_conf the conf maps containing the main.cfg settings * @param request the map containing the HTTP request * @param s the service structure * @param real_inputs the maps containing the inputs * @param real_outputs the maps containing the outputs */ int zoo_php_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ maps* m=*main_conf; maps* inputs=*real_inputs; maps* outputs=*real_outputs; map* libp = getMapFromMaps(m, "main", "libPath"); int res=SERVICE_FAILED; map* tmp=getMap(s->content,"serviceProvider"); if (tmp == NULL || tmp->value == NULL) { return errorException(m, "Missing serviceProvider (library file)", "NoApplicableCode", NULL); } map* cwd=getMapFromMaps(m,"lenv","cwd"); #ifdef IGNORE_METAPATH map* mp = createMap("metapath", ""); #else map* mp = getMap(request, "metapath"); #endif char *scriptName; if (libp != NULL && libp->value != NULL) { scriptName = (char*) malloc((strlen(libp->value) + strlen(tmp->value) + 2)*sizeof(char)); sprintf (scriptName, "%s/%s", libp->value, tmp->value); } else { if(mp!=NULL && strlen(mp->value)>0){ scriptName=(char*)malloc((strlen(cwd->value)+strlen(mp->value)+strlen(tmp->value)+3)*sizeof(char)); sprintf(scriptName,"%s/%s/%s",cwd->value,mp->value,tmp->value); }else{ scriptName=(char*)malloc((strlen(cwd->value)+strlen(tmp->value)+2)*sizeof(char)); sprintf(scriptName,"%s/%s",cwd->value,tmp->value); } } zend_file_handle iscript; iscript.type=ZEND_HANDLE_FD; iscript.opened_path=NULL; iscript.filename=tmp->value; iscript.free_filename=0; FILE* temp=fopen(scriptName,"rb"); if(temp==NULL){ char tmp1[1024]; sprintf(tmp1,_("Unable to load the PHP file %s"),tmp->value); free(scriptName); return errorException(m,tmp1,"NoApplicableCode",NULL); } iscript.handle.fd=fileno(temp); php_embed_init(0,NULL PTSRMLS_CC); zend_try { zend_startup_module(&zoo_module_entry); php_execute_script(&iscript TSRMLS_CC); zval *iargs[3]; zval iret, ifunc,ifile; ZVAL_STRING(&ifunc, s->name, 0); iargs[0] = php_Array_from_maps(*main_conf); iargs[1] = php_Array_from_maps(*real_inputs); iargs[2] = php_Array_from_maps(*real_outputs); if((res=call_user_function(EG(function_table), NULL, &ifunc, &iret, 3, iargs TSRMLS_CC))==SUCCESS){ HashTable* t=HASH_OF(iargs[2]); HashTable* t1=HASH_OF(iargs[0]); freeMaps(real_outputs); free(*real_outputs); freeMaps(main_conf); free(*main_conf); *real_outputs=php_maps_from_Array(t); *main_conf=php_maps_from_Array(t1); res=Z_LVAL(iret); }else{ free(scriptName); fclose(temp); return errorException(m,"Unable to process.","NoApplicableCode",NULL);; } } zend_catch { free(scriptName); fclose(temp); return errorException(m,"Unable to process.","NoApplicableCode",NULL);; } zend_end_try(); free(scriptName); fclose(temp); php_embed_shutdown(TSRMLS_C); return res; }
static PyObject * pyhp_evaluate_or_execute(int mode, PyObject *self, PyObject *args) { char *script, *tmp_buf; size_t tmp_buf_len; int zend_ret = 0; PyObject *d, *rv; zend_file_handle file_handle; #ifdef ZTS void ***tsrm_ls; #endif if (!PyArg_ParseTuple(args, "sO!", &script, &PyDict_Type, &d)) return NULL; /* Prepare stdout buffer. */ tmp_buf = stdout_buf; tmp_buf_len = stdout_buf_len; stdout_buf = malloc(1); if (stdout_buf == NULL) { PyErr_NoMemory(); return NULL; } stdout_buf[0] = 0; stdout_buf_len = 0; if (env_refcount++ == 0) { php_embed_init(0, NULL PTSRMLS_CC); pyhp_init_python_object_proxy(); } zend_first_try { /* Set PHP variables. */ if (pyhp_set_php_vars(d)) { if (stdout_buf != NULL) free(stdout_buf); return NULL; } /* Evaluate PHP script. */ if (mode == 0) { zend_ret = zend_eval_string(script, NULL, "" TSRMLS_CC); } else { file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = script; file_handle.free_filename = 0; file_handle.opened_path = NULL; zend_ret = php_execute_script( &file_handle TSRMLS_CC ); } } zend_catch { } zend_end_try(); if (--env_refcount == 0) { php_embed_shutdown(TSRMLS_C); } /* Create return value from stdout buffer. */ if (stdout_buf == NULL) { rv = NULL; } else { /* If error occurs, rv will be NULL. */ if (zend_ret == FAILURE) { PyErr_SetString(PyExc_RuntimeError, "PHP script failed to execute"); rv = NULL; } else { rv = Py_BuildValue("s", stdout_buf); } free(stdout_buf); } stdout_buf = tmp_buf; stdout_buf_len = tmp_buf_len; return rv; }
static VALUE stop(VALUE self) { php_embed_shutdown(); return Qnil; }
/* {{{ goemphp php_shutdown() */ void php_shutdown(void) { php_embed_shutdown(TSRMLS_CC); }