简体   繁体   English

从php调用c

[英]calling c from php

我想知道是否有一种方法可以从php调用现有的C代码?

If your C code is compiled to an executable, that executable can be executed from PHP -- but I'm guessing this is not quite what you meant ? 如果将您的C代码编译为可执行文件,则可以从PHP执行该可执行文件-但我猜这不是您的意思吗?

If you want to excute C code from PHP : that is not possible... unless you compile your C code to a PHP extension. 如果您想从PHP中提取C代码,那是不可能的...除非您将C代码编译为PHP扩展。

A PHP extension is like a .dll , on windows : it's a library, that can export functions that can be called from PHP. PHP扩展名类似于Windows上的.dll :它是一个库,可以导出可以从PHP调用的函数。


If you want to learn more about writing PHP extensions, those links will probably interest you : 如果您想了解有关编写PHP扩展的更多信息,那么您可能会喜欢这些链接:

And, if you are really interested by the subject, and ready to spend some money on it, you could buy the book Extending and Embedding PHP ( some pages are available as preview on Google Books too) ; 并且,如果您真的对这个主题感兴趣,并准备花一些钱,可以购买本书Extending and Embedding PHP 有些页面也可以在Google图书中作为预览使用 It's considered as the book to read when interested on this subject (In fact, I've bought it some time ago, and, in my opinion, it is indeed an interesting read) 如果您对此主题感兴趣,可以其视为要阅读(实际上,我已经购买了一段时间,在我看来,这确实是一本有趣的书)

BTW, the author of that book is also the author of the first four articles I linked to ;-) 顺便说一句,这本书的作者还是我链接到;-)的前四篇文章的作者

This article talks about PHP-C++ bindings. 文章关于PHP-C ++绑定会谈。 May be of help. 可能会有帮助。 In particular, checkout the BEGIN_EXTERN_C/END_EXTERN_C macros. 特别是,检出BEGIN_EXTERN_C / END_EXTERN_C宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM