如何从.so文件使用php脚本调用函数? [英] How to call function from .so file using php script?

查看:201
本文介绍了如何从.so文件使用php脚本调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为以下函数创建了.so文件:



main.cpp:

 #include< stdio.h> 
#includetest.h
int main()
{
int a = hello();
printf(%d,a);
return 0;
}



test.h

  int test()
{
int a = 5,b = 10,c;
printf(Hi);
c = a + b;
return c;
}


$ b $ p现在我为上面的程序创建共享库文件main.so,

  

<?php
//调用main.cpp中的测试函数
>

我在网上看到了各种教程,但没有清楚的解释。

解决方案

Sara Goleman的书是一本出色的,全面的(包括您的主题)。



这是一篇介绍性的文章。



http://devzone.zend.com/303/ extension-writing-part-i-introduction-to-php-and-zend /



我读过她的书,完全覆盖了这个问题。



http://www.amazon。 com / dp / 067232704X



很抱歉,如果这不是一个快速而简单的答案。但是,PHP API并不完全直接。如果没有关于每个组件的进一步的背景信息,这是没有意义的。一旦我这样做,我就可以清楚地看到PHP API的开发。



或者,如果你正在寻找一个不同的方法,使用RabbitMQ或一些其他消息队列服务可能需要调用c ++应用程序并从(可选)持久性c ++进程来回发送消息。



这里有一些我发现的链接有用:



http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/



http://talks.somabo.de/200903_montreal_php_extension_writing.pdf



http: //simonholywell.com/post/2010/09/15-excellent-resources-for-php-extension-development.html



http://blog.golemon.com/2006/06/what-heck -is-tsrmlscc-anyway.html



http://www.php.net/manual/en/internals2.php


I have created .so file for following function:

main.cpp:

#include<stdio.h>
#include "test.h"
int main()
{
int a=hello();
printf("%d",a);
return 0;
}

test.h

int test()
{
 int a=5,b=10,c;
 printf("Hi");
 c=a+b;
 return c;
}

Now I create shared library file main.so for above program and want to call hell() function from php script.

p1.php

<?php
// Call to test function in main.cpp
>

I saw various tutorials on web but no clear explaination. Can someone give link to some tutorial or help me for this prob?

解决方案

Sara Goleman's book is an excellent, thorough coverage of how to develop php extensions (including your topic).

Here is an introductory article.

http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/

I've read her book and it covers this question entirely.

http://www.amazon.com/dp/067232704X

I'm sorry if this isn't a quick and easy answer. However, the PHP API isn't exactly straight forward. It didn't quite make sense without further background information on each of the components. Once I had that, I was able to see PHP API development clearly.

Alternatively, if you're looking for a different approach, using RabbitMQ or some other message queue service may be desirable to invoke a c++ application and send messages back and forth from (optionally) a persistent c++ process.

Here are some further links that I've found to be useful:

http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/

http://talks.somabo.de/200903_montreal_php_extension_writing.pdf

http://simonholywell.com/post/2010/09/15-excellent-resources-for-php-extension-development.html

http://blog.golemon.com/2006/06/what-heck-is-tsrmlscc-anyway.html

http://www.php.net/manual/en/internals2.php

这篇关于如何从.so文件使用php脚本调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆