PHP5 call external C library, solve the idea

Source: Internet
Author: User
PHP5 call external C library, nasty!
---------external C function hello.c----------
#include
#include
#include
#include
#include
int hello_cc (char * dbg)
{
Syslog (Log_debug, "hello_cc%s\n", DBG);
if (dbg==null) return-1;
if (strlen (DBG) >1024) return-1;
printf ("%s\n", DBG);
Syslog (Log_debug, "hello_cc return\n");
return 0;
}
---------php5 extension function hello.c-----------
Const Zend_function_entry hello_functions[] = {
Php_fe (confirm_hello_compiled, NULL)/* For testing, remove later. */
Php_fe (Hello, NULL)
Php_fe_end/* Must be the last line in hello_functions[] */
};
Php_function (confirm_hello_compiled)
{
char *arg = NULL;
int Arg_len, Len;
Char *STRG;

if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "s", &arg, &arg_len) = = FAILURE) {
Return
}

Len = spprintf (&STRG, 0, "congratulations! You have successfully modified EXT/%.78S/CONFIG.M4. Module%.78s is now compiled to PHP. "," Hello ", arg$
Return_stringl (STRG, Len, 0);
}
Php_function (Hello) {
char *dbg = NULL;
int Dbg_len, Len;
int result;

if (Zend_parse_parameters (Zend_num_args () tsrmls_cc, "s", &dbg, &dbg_len) = = FAILURE) {
Return
}
RES_CC = HELLO_CC (DBG);
Return_long (RES_CC);
}
------------PHP5 Call-------------
if (!extension_loaded ("Hello")) {
print "Skip";
} else {
DL (' hello.so '); PHP5 in DL () is masked and added directly to the php.ini hello.so
echo Hello ("SSSSSSSSQQQQQQQQQQQQ");
}

Output-->> blank page, estimated to have collapsed.
Solve the correct php_function (hello), Emergency!!!

------Solution--------------------
If the HELLO_CC definition is not wrong, put it together and compile it.

But you're in the hello_cc. printf seems to violate the convention of PHP extension.
  • 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.