Using PHP write extension to call C language function interfaces has anyone studied using PHP write extension to call C language function interfaces? I now have a C language function interface that is compiled into a. so file. Now the front-end will call this C language interface. I checked it online and want to write PHP Extensions. I used PHP to package C interfaces into extension modules. I have tested C functions without parameters or integer parameters that can be successfully called by PHP. However, for C functions with pointer parameters, after packaging them as extensions, but the call fails. I have been using PHP to write extensions to call C language function interfaces.
Has anyone studied using PHP to write extensions to call C language function interfaces?
I now have a C language function interface that is compiled into a. so file. Now the front-end will call this C language interface. I checked it online and want to write PHP Extensions. I used PHP to package C interfaces into extension modules. I have tested C functions without parameters or integer parameters that can be successfully called by PHP. However, for C functions with pointer parameters, after packaging them as extensions, but the call fails. I have never understood the cause. My code is as follows. please kindly advise.
C function :( finally compiled into the libtest. so file)
Char * test (char * arg)
{
Return arg;
}
Write a PHP module phptest:
The code in the phptest. c file is as follows:
155 PHP_FUNCTION (test)
156 {
158 char * arg;
159 int arg_len;
160 char * result;
161 // int result_len;
162
163 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, "s", & arg, & arg_len) = FAILURE ){
164 return;
165}
166 result = (char *) emalloc (50 );
167
168 result = memcpy (result, test (arg), 50 );
169 // result = "hello abc ";
170 RETURN_STRING (result, 1 );
171}
------ Solution --------------------
Recently I have been studying C.
------ Solution --------------------
Discussion
Has anyone studied using PHP to write extensions to call C language function interfaces?
I now have a C language function interface that is compiled into a. so file. Now the front-end will call this C language interface. I checked it online and want to write PHP Extensions. I used PHP to package C interfaces into extension modules. I have tested C functions without parameters or integer parameters that can be successfully called by PHP. However, for C functions with pointer parameters, after packaging them as extensions, but the call fails. I have never understood the cause. My code is as follows. please kindly advise.
C function :( finally compiled into libt ......