/* {{{ goemphp php_eval_script(script) */ char * php_eval_script(char *script) { char *result = NULL; zend_first_try { zend_eval_string(script, NULL, "GoEmPHP" TSRMLS_CC); // executed failure, get error message if (PG(last_error_message)) { result = strdup(PG(last_error_message)); free(PG(last_error_message)); PG(last_error_message) = NULL; } if (PG(last_error_message)) { result = strdup(PG(last_error_message)); free(PG(last_error_message)); PG(last_error_message) = NULL; } if (!result && EG(exception)) { result = exception_error(EG(exception), E_ERROR TSRMLS_CC); EG(exception) = NULL; } // trigger_error & throw exception need to handle // if (error) { // // } else if (exception) { // // } } zend_end_try(); return result; }
static VALUE native_eval(VALUE self, VALUE string, VALUE filename) { zval return_value; zend_first_try { zend_eval_string( StringValuePtr(string), NULL, StringValuePtr(filename) ); } zend_end_try(); return Qnil; }
bool samphp::loadGamemode() { std::string gamemode = GetServerCfgOption("samphpmode"); if(gamemode.length() > 0) { gamemode = "php/" + gamemode + "/gamemode.php"; } else { gamemode = "php/gamemode.php"; } zend_first_try { char *filename = (char *) gamemode.c_str(); char *include_script; spprintf(&include_script, 0, "require '%s';", filename); zend_eval_string(include_script, NULL, filename TSRMLS_CC); efree(include_script); } zend_end_try(); return true; }
int main(int argc, char **argv) { int retval = SUCCESS; char *code = "if (file_exists($file = __DIR__.\"/Resources/app.phar\")) {" "require $file;" "} else {" "echo 'Could not locate app archive'.PHP_EOL;" "}"; char buf[PATH_MAX]; char* dir = dirname(buf); php_embed_module.php_ini_ignore = 0; php_embed_module.php_ini_path_override = "./encore.ini"; PHP_EMBED_START_BLOCK(argc,argv); zend_alter_ini_entry("extension_dir", 14, dir, strlen(dir), PHP_INI_ALL, PHP_INI_STAGE_ACTIVATE); zend_alter_ini_entry("error_reporting", 16, "0", 1, PHP_INI_ALL, PHP_INI_STAGE_ACTIVATE); retval = zend_eval_string(code, NULL, argv[0] TSRMLS_CC) == SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; PHP_EMBED_END_BLOCK(); exit(retval); }
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; }