PHP 開發擴展 C++ 庫:PHP-CPP
PHP-CPP是一個用于開發PHP擴展的C++庫。它提供了一套詳實易用的類,用于開發PHP擴展。

示例1:
Php::Value hello_world(){
return "hello world!";} 示例2:
#include <phpcpp.h>
/**
* Global variable that stores the number of times
* the function updateCounters() has been called in total
* @var int
*/
int invokeTotalCount = 0;
/**
* Global variable that keeps track how many times the
* function updateCounters() was called during the
* current request
* @var int
*/
int invokeDuringRequestCount = 0;
/**
* Native function that is callable from PHP
*
* This function updates a number of global variables that count
* the number of times a function was called
*/
void updateCounters()
{
// increment global counters
invokeTotalCount++;
invokeDuringRequestCount++;
}
/**
* Switch to C context, because the Zend engine expects get get_module()
* to have a C style function signature
*/
extern "C" {
/**
* Startup function that is automatically called by the Zend engine
* when PHP starts, and that should return the extension details
* @return void*
*/
PHPCPP_EXPORT void *get_module()
{
// the extension object
static Php::Extension extension("my_extension", "1.0");
// install a callback that is called at the beginning
// of each request
extension.onRequest([]() {
// re-initialize the counter
invokeDuringRequestCount = 0;
});
// add the updateCounter method to the extension
extension.add("updateCounters", updateCounters);
// return the extension details
return extension;
}
}
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!