我如何使用 C++与 PHP 交互的代码?

发布于 2024-08-05 21:05:01 字数 1539 浏览 9 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

别把无礼当个性 2024-08-12 21:05:01

您可以向 PHP 添加函数/类,用 C 编程(如果我没记错的话,您可以从 C 封装 C++ 类),这可能允许您这样做有些事情更快——如果编程得好:不需要解释 PHP 代码;仅执行机器代码,通常速度更快。

为此,您必须开发一个 PHP 扩展

互联网上没有太多可用的资源,但这些资源可能会帮助您开始:

而且,特别是关于 C++ 部分,这个也可能有帮助:

如果你真的对这个主题感兴趣,并且准备花一些钱,你也可以购买这本书 扩展和嵌入 PHP (某些页面可用作也可在 Google 图书上预览;我曾多次看到这是一本对这个主题感兴趣时值得一读的书(事实上,我已经买了它一段时间了,读起来很有趣)< /em>

顺便说一下,那本书的作者也是我链接到的前四篇文章的作者;-)

You can add functions/classes to PHP, programmed in C (and you can wrap a C++ class from C, if I remember correctly from an article I read some time ago), which might allow you to do some things faster -- if programmed well : no need for interpretation of PHP code ; only execution of machine code, which is generally way faster.

To do that, you'll have to develop a PHP extension.

There are not that many resources available on the Internet about that, but these one might help you to start :

And, specifically about the C++ part, this one might help too :

If you are really interested by the subject, and ready to spend some money on it, you could also buy the book Extending and Embedding PHP (some pages are available as preview on Google Books too) ; I've seen a couple of times that it was the book to read when interested on this subject (In fact, I've bought it some time ago, and it's an interesting read)

By the way, the author of that book is also the author of the first four articles I linked to ;-)

秉烛思 2024-08-12 21:05:01

实际上,您可以执行编译的应用程序,而无需任何类型的 API:

$output = exec('/path/to/yourapp');

除此之外,您始终可以编写 PHP 扩展。这里有一个关于这个主题的很好的指南:http://devzone.zend.com/article/1021

You can actually execute compiled applications without any sort of API:

$output = exec('/path/to/yourapp');

Beyond that, you could always write a PHP extension. There's a good guide on the subject here: http://devzone.zend.com/article/1021

飘然心甜 2024-08-12 21:05:01

swig,简化的包装器和接口生成器可以帮助您将(现有的)c++ 包装到 php 模块中。

SWIG 是一种软件开发工具,它将用 C 和 C++ 编写的程序与各种高级编程语言连接起来。 SWIG 可与不同类型的语言一起使用,包括 Perl、PHP、Python、Tcl 和 Ruby 等常见脚本语言。

swig, the Simplified Wrapper and Interface Generator can help you wrapping (existing) c++ into a php module.

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby.

初雪 2024-08-12 21:05:01

好吧,您还没有定义您想要执行的操作,但如果您需要 C++ 接口,请查看源代码中的 ext 目录,以了解如何编写 PHP 扩展,然后您可以从 PHP 脚本加载和使用该扩展。

一些可能有帮助的链接:

http ://www.devarticles.com/c/a/Cplusplus/Developing-Custom-PHP-Extensions-Part-1/
http://devzone.zend.com/article/1021

Well you have not defined what you are trying to do, but if you need to the C++ interface, then look at the ext directory in the source code to understand how to write a PHP extension that you can then load and use from your PHP scripts.

A couple of links that may help:

http://www.devarticles.com/c/a/Cplusplus/Developing-Custom-PHP-Extensions-Part-1/
http://devzone.zend.com/article/1021

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文