Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25607 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51652 invoked by uid 1010); 11 Sep 2006 13:22:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 51637 invoked from network); 11 Sep 2006 13:22:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Sep 2006 13:22:34 -0000 X-Host-Fingerprint: 70.126.65.55 55-65.126-70.tampabay.res.rr.com Received: from [70.126.65.55] ([70.126.65.55:13497] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 70/2C-02095-91365054 for ; Mon, 11 Sep 2006 09:22:34 -0400 Message-ID: <70.2C.02095.91365054@pb1.pair.com> To: internals@lists.php.net Date: Mon, 11 Sep 2006 09:22:34 -0400 User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 References: <27.89.02095.A8A55054@pb1.pair.com> <45055FF0.4010206@schlueters.de> In-Reply-To: <45055FF0.4010206@schlueters.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Posted-By: 70.126.65.55 Subject: Re: [PHP-DEV] SAPI EMBED Problems From: brian@attdv.com (Brian Fertig) Johannes Schlueter wrote: > Not without code, backtrace, etc. > > johannes > > Brian Fertig wrote: >> I wrote an embedded application that can execute php scripts. >> When the script exits and I call the php_embed_shutdown() function >> it crashes. Can someone explain to me how I can keep this from >> happening? >> >> >> Brian >> >> this is the code ---------------- > static void php_function(switch_core_session_t *session, char *data) > { > char *uuid = switch_core_session_get_uuid(session); > uint32_t ulen = strlen(uuid); > uint32_t len = strlen((char *) data) + ulen + 2; > char *mydata = switch_core_session_alloc(session, len); > int argc, retval; > char *argv[5]; > char php_code[1024]; > void*** tsrm_ls = NULL; > > snprintf(mydata, len, "%s %s", uuid, data); > > argc = switch_separate_string(mydata, ' ',argv,(sizeof(argv) / sizeof(argv[0]))); > > sprintf(php_code, "uuid=\"%s\"; include(\"%s\");\n", argv[0], argv[1]); > //sprintf(php_code, "include('%s');", argv[1]); > > sprintf(php_code, "%s %s", data, uuid); > > zend_file_handle script; > script.type = ZEND_HANDLE_FP; > script.filename = data; > script.opened_path = NULL; > script.free_filename = 0; > script.handle.fp = fopen(script.filename, "rb"); > > // Initialize PHPs CORE > php_embed_init(argc, argv, &tsrm_ls); > > // Return All of the DEBUG crap to the console and/or a log file > php_embed_module.ub_write = sapi_mod_php_ub_write; > php_embed_module.log_message = mod_php_log_message; > php_embed_module.sapi_error = (sapi_error_function_t)mod_php_error_handler; > > // Let the nice people know we are about to start their script > switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting Script %s\n",data); > > // Force $uuid and $session to exist in PHPs memory space > zval *php_uuid; > MAKE_STD_ZVAL(php_uuid); > //MAKE_STD_ZVAL(php_session); > //php_uuid->type = IS_STRING; > //php_uuid->value.str.len = strlen(uuid); > //php_uuid->value.str.val = estrdup(uuid); > ZVAL_STRING(php_uuid, uuid , 1); > //ZVAL_STRING(php_session, session , 1); > ZEND_SET_SYMBOL(&EG(symbol_table), "uuid", php_uuid); > //ZEND_SET_SYMBOL(&EG(active_symbol_table), "session", php_session); > > // Force Some INI entries weather the user likes it or not > zend_alter_ini_entry("register_globals",sizeof("register_globals"),"1", sizeof("1") - 1, PHP_INI_SYSTEM, PHP_INI_STAGE_RUNTIME); > > // Execute the bloody script > retval = php_execute_script(&script TSRMLS_CC); > > // Clean up after PHP and such > php_embed_shutdown(tsrm_ls); It freaks out down here when it calls tsrm_shutdown() it just stops the whole server. > > > > // Return back to the Dialplan > > // Buh bye now! > }