PHP7.4 已经有 preload 和 ffi 了?
https://www.php.net/manual/en/ffi.examples-complete.php
现在 php 可以直接调用 c 代码了,openresty 的 luajit 调用 c 也是用的 ffi
现在 php 可以直接调用 c 代码了,openresty 的 luajit 调用 c 也是用的 ffi
https://segmentfault.com/a/1190000021234312 发个当年翻译和整理的关于 preload 的文章
这么复杂我为什么不用 Go ?
void helloworld()
{
printf(“hello world!n”);
}
<?php
$ffi = ffi::cdef(
“void helloworld();”,
“./libhelloworld.so”
);
$ffi->helloworld();
[email protected]:~/phpffi/helloworld$ php helloworld.php
hello world!
[email protected]:~/phpffi/helloworld$ php –version
PHP 7.4.11 (cli) (built: Oct 10 2020 19:44:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
[email protected]:~/phpffi/helloworld$ php -m | grep -i ffi
FFI
不过总要有人踏出第一步,后人继续完善。