Problems related to calling C language function interfaces using PHP write extension

Source: Internet
Author: User
Tags php write
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 ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.