Maxtor Posted March 5, 2009 Share Posted March 5, 2009 Hi all, I don't know if this is the right place to post my problem. If not seniors, please guide, I have been trying offlate to call PHP code in C. I have been able to run few of the examples from the book "Extending and Embedding PHP - Sara Golemon". But I have been having problems in extending further. My Problem is as follows: Whenever I use php_embed_init() and php_embed_shutdown() in a dll I create, the dll doesn't get loaded by my webserver when I try to load it as an additional module. I think something else needs to be loaded before my dll gets loaded, not sure what? Thank you for your time, Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/ Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 What webserver? Apache? The DLL will have to be compatible with the Apache module API. Edit: Or did you make a PHP module and the PHP module isn't loading? Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/#findComment-777741 Share on other sites More sharing options...
Maxtor Posted March 6, 2009 Author Share Posted March 6, 2009 Sorry, not mentioned this in the post earlier, I am using Apache/2.2.4 (Win32), PHP Version 5.2.3 I am creating a PHP module and make a call to "call_user_function()". A small piece of I am doing is as follows: // FirstPHPExt.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #ifdef ZTS void ***tsrm_ls; #endif long retval; /* declaration of functions to be exported */ ZEND_FUNCTION(DoubleUp); void testing() { int argc=2; char *argv[] = {"test"}; if (php_embed_init(1, argv PTSRMLS_CC) == FAILURE) { } //PHP_EMBED_START_BLOCK(argc, argv); zval fname,return_value; zval *params; MAKE_STD_ZVAL(params); //MAKE_STD_ZVAL(params[1]); ZVAL_STRING(&fname, "MyFunction", 1); ZVAL_STRING(params, "test", 1); if (call_user_function(EG(function_table), NULL, &fname, &return_value, 1, ¶ms TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call MyFunction(), is it defined?"); // RETVAL_FALSE; goto cleanup; } cleanup: zval_dtor(&fname); zval_dtor(params); //zval_dtor(¶ms[1]); //PHP_EMBED_END_BLOCK(); php_embed_shutdown(TSRMLS_C); } #ifdef __cplusplus extern "C" { #endif void onMessage(HOBJ msg); /* to handle message subscriptions */ #ifdef __cplusplus }; #endif /* compiled function list so Zend knows what's in this module */ zend_function_entry FirstPHPExtModule_functions[] = { ZEND_FE(DoubleUp, NULL) {NULL, NULL, NULL} }; /* compiled module information */ zend_module_entry FirstPHPExtModule_module_entry = { STANDARD_MODULE_HEADER, "FirtsPHPExt Module", FirstPHPExtModule_functions, NULL, NULL, NULL, NULL, NULL, NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; /* implement standard "stub" routine to introduce ourselves to Zend */ ZEND_GET_MODULE(FirstPHPExtModule) /* DoubleUp function */ /* This method takes 1 parameter, a long value, returns the value multiplied by 2 */ ZEND_FUNCTION(DoubleUp){ long paramValue = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", ¶mValue) == FAILURE) { RETURN_STRING("Bad parameters!", true); } testing(); paramValue *= 2; RETURN_LONG(paramValue); } #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } #ifdef _MANAGED #pragma managed(pop) #endif Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/#findComment-777877 Share on other sites More sharing options...
corbin Posted March 7, 2009 Share Posted March 7, 2009 Are you including php.h anywhere? Also, you are building this as a PHP module right, not just a stand alone DLL? Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/#findComment-778734 Share on other sites More sharing options...
Maxtor Posted March 9, 2009 Author Share Posted March 9, 2009 Ya I have php.h and yes I am building a PHP module and not a standalone dll, Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/#findComment-780103 Share on other sites More sharing options...
corbin Posted March 9, 2009 Share Posted March 9, 2009 You are trying to load it in PHP and not Apache right? ("the dll doesn't get loaded by my webserver") Is there an error in the error log? Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/#findComment-780671 Share on other sites More sharing options...
Maxtor Posted March 11, 2009 Author Share Posted March 11, 2009 As I showed in the code I posted, I have functions "DoubleUp" and "testing". I make a call to the function "testing" from within the function "DoubleUp", which calls the method php_embed_init(). Whenever I include this portion of the code and compile my dll, void testing() { int argc=2; char *argv[] = {"test"}; if (php_embed_init(1, argv PTSRMLS_CC) == FAILURE) { } //PHP_EMBED_START_BLOCK(argc, argv); zval fname,return_value; zval *params; MAKE_STD_ZVAL(params); //MAKE_STD_ZVAL(params[1]); ZVAL_STRING(&fname, "MyFunction", 1); ZVAL_STRING(params, "test", 1); if (call_user_function(EG(function_table), NULL, &fname, &return_value, 1, ¶ms TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call MyFunction(), is it defined?"); // RETVAL_FALSE; goto cleanup; } cleanup: zval_dtor(&fname); zval_dtor(params); //zval_dtor(¶ms[1]); //PHP_EMBED_END_BLOCK(); php_embed_shutdown(TSRMLS_C); } I get this error at the xampp startup and the module doesn't get loaded. [11-Mar-2009 09:28:33] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\m y_php_ext.dll' - The specified module could not be found. If I compiled the dll without the above function, the module is loaded perfectly fine. You are trying to load it in PHP and not Apache right? ("the dll doesn't get loaded by my webserver") I think I might be wrong at this saying that the dll is loaded by the webserver, The way I load the dll is: 1. Compile the dll, 2. Place it in the ext direct of PHP 3. Edit the php.ini to load my dll "my_php_ext.dll" 4. Start the xampp server, Thank you Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/#findComment-781813 Share on other sites More sharing options...
Maxtor Posted March 11, 2009 Author Share Posted March 11, 2009 Also when I try to use call_user_function() I get a Access Violation Error at the point where I call call_user_function(), void testing() { zval funcname; char *string_contents = "MessageHandler"; ZVAL_STRING(&funcname, "MessageHandler", 0); if(call_user_function(EG(function_table), NULL, &funcname, &returnval, 1, NULL TSRMLS_CC) != SUCCESS) { zend_error(E_ERROR, "Function call failed"); } } Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/#findComment-781889 Share on other sites More sharing options...
corbin Posted March 11, 2009 Share Posted March 11, 2009 Hrmmm that probably means that something is wrong with the parameters to call_user_function. Link to comment https://forums.phpfreaks.com/topic/148076-php_embed_init/#findComment-782362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.