samphp::samphp(bool typeError) { int argc = 1; char *argv[2] = { "samp03svr", NULL }; php_embed_module.ub_write = samphp_output_handler; php_embed_module.sapi_error = &samphp::error_wrap; php_embed_module.log_message = samphp_error_handler; php_embed_init(argc, argv PTSRMLS_CC); zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); zend_alter_ini_entry("implicit_flush", 15, "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); zend_alter_ini_entry("variables_order", 16, "S", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); SG(options) |= SAPI_OPTION_NO_CHDIR; SG(headers_sent) = 1; SG(request_info).no_headers = 1; PG(during_request_startup) = 0; php_set_ini_entry("max_execution_time", "0", PHP_INI_STAGE_ACTIVATE); zend_unset_timeout(TSRMLS_C); php_set_ini_entry("variables_order", "S", PHP_INI_STAGE_ACTIVATE); #ifdef ZEND_WIN32 php_set_ini_entry("include_path", ".;./php", PHP_INI_SYSTEM); #else php_set_ini_entry("include_path", ".:./php", PHP_INI_SYSTEM); #endif }
static VALUE start(VALUE self) { /* FIXME: * I got these from the book. I don't know wtf they're for yet. */ int argc = 1; char *argv[2] = { "embed4", NULL }; /* end FIXME */ php_embed_module.ub_write = phuby_ub_write; php_embed_module.header_handler = phuby_header_handler; php_embed_init(argc, argv); return Qnil; }
int main( int argc, char **argv ) { char *scrFile; int scrArgc; int status; int numLoop; int i; if ( argc < 3 ) { fprintf( stderr, "usage: phptest n scriptFile argv ...\n" ); exit( 1 ); } numLoop = atoi( argv[1] ); if ( numLoop <= 0 || numLoop > 10000 ) { fprintf( stderr, "usage: phptest n scriptFile argv ...\n" ); exit( 1 ); } scrFile = argv[2]; /* the count includes the script file */ scrArgc = argc - 2; static char *myargv[2] = {"irodsPhp", NULL}; if ( php_embed_init( 1, myargv PTSRMLS_CC ) == FAILURE ) { fprintf( stderr, "php_embed_init failed\n" ); exit( 1 ); } php_embed_module.executable_location = argv[0]; for ( i = 0; i < numLoop; i++ ) { status = execPhpScript( scrFile, scrArgc, &argv[2] ); if ( status < 0 ) { fprintf( stderr, "execPhpScript of %s error, status = %d\n", argv[1], status ); break; } } phpShutdown(); exit( status ); }
/* This function loads the PHP interpreter if it doesn't exist already. * then it executes the PHP file */ void myphp_eval_file(char *filename) { zend_file_handle file_handle; static int has_started = 0; FILE *fp; /* For some reason PHP is segfaulting because a PHP file * does not exist. Here's a cheap check */ if ((fp = fopen(filename, "r")) == NULL) { troll_debug(LOG_WARN, "Could not open (%s) for PHP evaluation.", filename); return; } fclose(fp); TSRMLS_FETCH(); if (has_started == 0) { php_embed_init(0,NULL PTSRMLS_CC); has_started = 1; } file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = filename; file_handle.free_filename = 0; file_handle.opened_path = NULL; zend_try { if (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, &file_handle) != SUCCESS) troll_debug(LOG_WARN,"PHP Script (%s) could not be run",filename); else troll_debug(LOG_DEBUG,"PHP Script (%s) successfully loaded",filename); } zend_end_try(); return; }
static void __attribute__((constructor)) init() { php_embed_init(0, NULL PTSRMLS_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; }
/* {{{ goemphp php_startup(ini) */ void php_startup() { php_embed_init(0, NULL PTSRMLS_CC); if (zend_register_functions(NULL, go_functions, CG(function_table), MODULE_PERSISTENT TSRMLS_CC) == FAILURE) { } }