feat(extension): 添加请求生命周期钩子函数支持

- 在扩展模板中添加 PHP_RINIT 和 PHP_RSHUTDOWN 函数实现
- 配置模块入口结构以启用请求初始化和关闭回调
- 更新主程序初始化逻辑以使用模块生命周期函数
- 实现请求启动和关闭时的应用程序初始化清理功能
- 解决 PHP 内部字符串处理的双释放问题
- 简化示例代码以演示全局变量访问功能
pull/1/head
韩天峰 7 months ago
parent 6632629f58
commit 5b44e4d390
  1. 2
      src/Php/CompilerBase.php
  2. 6
      src/Php/Translator.php
  3. 1
      src/cpp/main.cc
  4. 20
      src/cpp/php_aot_helper.h

@ -84,6 +84,7 @@ class CompilerBase extends \PhpAot\Core\Translator
'phpx_func.h',
'php_func_decl.h',
'php_global_var_decl.h',
'php_aot_helper.h',
];
protected array $localHeaders = [];
protected array $nativeFunctions = [];
@ -1395,6 +1396,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$list = [
$this->phpxDir . '/include',
$this->getBuildDir() . '/include',
$this->rootPath . '/src/cpp',
];
$out = '$(php-config --includes) ';
foreach ($list as $li) {

@ -294,12 +294,6 @@ class Translator extends Preprocessor
foreach ($this->nativeConstants as $name => $constant) {
$code .= 'extern ' . $constant->type . ' ' . $name . ';' . PHP_EOL;
}
$code .= 'extern zend_class_entry *php_get_class(int class_id, const char *class_name);' . PHP_EOL;
$code .= 'extern zend_function *php_get_func(int func_id, const char *func_name);' . PHP_EOL;
$code .= '#define CALL(id, name, args) php::call(php_get_func(id, name), args)' . PHP_EOL;
$code .= '#define CALL_SILENT(id, name, args) php::silentCall(php_get_func(id, name), args)' . PHP_EOL;
$this->writeFile($file, $code);
}

@ -52,6 +52,7 @@ int main(int cpp_argc, char **cpp_argv) {
#endif
module->request_shutdown_func(module->type, module->module_number);
module_shutdown(module);
php_embed_shutdown();
return rc;

@ -0,0 +1,20 @@
#include <phpx.h>
extern zend_class_entry *php_get_class(int class_id, const char *class_name);
extern zend_function *php_get_func(int func_id, const char *func_name);
static inline php::Variant CALL(int func_id, const char *func_name, const std::initializer_list<php::Variant> &args) {
return php::call(php_get_func(func_id, func_name), args);
}
static inline php::Variant CALL(int func_id, const char *func_name) {
return php::call(php_get_func(func_id, func_name));
}
static inline php::Variant CALL_SILENT(int func_id, const char *func_name, const std::initializer_list<php::Variant> &args) {
return php::silentCall(php_get_func(func_id, func_name), args);
}
static inline php::Variant CALL_SILENT(int func_id, const char *func_name) {
return php::silentCall(php_get_func(func_id, func_name));
}
Loading…
Cancel
Save