./configure –enable-debug –enable-phpdbg
make
make install
ext/opcache/jit/zend_jit_perf_dump.c:105:20: error: use of undeclared identifier
‘CLOCK_MONOTONIC’
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
#define CLOCK_MONOTONIC 0
https://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x
EX_CONSTANT 未定义问题
php7 和php8 不兼容,需要换一种方式
estatus = EX_CONSTANT(EX(opline)->op1);
estatus = RT_CONSTANT(EX(opline), EX(opline)->op1);
https://gist.github.com/cmb69/3060a552fc825497d066262ab31f3998
https://zhuanlan.zhihu.com/p/64144202
Installing shared extensions: /usr/local/lib/php/extensions/debug-non-zts-20190128/
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/php/man/man1/
Installing phpdbg binary: /usr/local/bin/
Installing phpdbg man page: /usr/local/php/man/man1/
Installing PHP CGI binary: /usr/local/bin/
Installing PHP CGI man page: /usr/local/php/man/man1/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/man/man1/
page: phpize.1
page: php-config.1
/Users/didi/PhpstormProjects/c/php-src/build/shtool install -c ext/phar/phar.phar /usr/local/bin/phar.phar
ln -s -f phar.phar /usr/local/bin/phar
Installing PDO headers: /usr/local/include/php/ext/pdo/
$php -v
Failed loading /usr/local/lib/php/extensions/debug-non-zts-20160303/xdebug.so: dlopen(/usr/local/lib/php/extensions/debug-non-zts-20160303/xdebug.so, 9): Symbol not found: _gc_globals
Referenced from: /usr/local/lib/php/extensions/debug-non-zts-20160303/xdebug.so
Expected in: flat namespace
in /usr/local/lib/php/extensions/debug-non-zts-20160303/xdebug.so
PHP Warning: PHP Startup: openssl: Unable to initialize module
Module compiled with module API=20160303
PHP compiled with module API=20190128
These options need to match
in Unknown on line 0
Warning: PHP Startup: slowLog: Unable to initialize module
Module compiled with module API=20160303
PHP compiled with module API=20190128
These options need to match
in Unknown on line 0
PHP Fatal error: Directive ‘track_errors’ is no longer available in PHP in Unknown on line 0
Fatal error: Directive ‘track_errors’ is no longer available in PHP in Unknown on line 0
vi /usr/local/lib/php.ini
注释掉扩展
In php.ini change
track_errors=On
to
track_errors=Off
https://github.com/SublimeLinter/SublimeLinter-phplint/issues/31
$php -v
PHP 8.0.0-dev (cli) (built: Jul 20 2020 12:11:10) ( NTS DEBUG )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
cd ext/al
phpize
./configure
make
make install
vi /usr/local/lib/php.ini
extension_dir = “/usr/local/lib/php/extensions/debug-non-zts-20190128/”
extension=al.so
php -m | grep al |
1 warning generated.
[100%] Linking C executable alae
Undefined symbols for architecture x86_64:
“_OnUpdateBool”, referenced from:
ini_entries in
ld: symbol(s) not found for architecture x86_64
原因:
修改php源码后,需要重新编译php,php扩展里加载php函数是从链接库里加载的,不是从源代码,所以找不到
针对不同版本的php,很容易出现不兼容问题,解决办法就是编译对应版本的php
https://stackoverflow.com/questions/40746352/symbols-not-found-for-architecture-x86-64-cmake-mac-sierra
https://blog.csdn.net/ligaofeng/article/details/52674696
https://segmentfault.com/q/1010000004137098
https://stackoverflow.com/questions/23534362/warning-treating-c-header-input-as-c-header-when-in-c-mode-this-behavi
zend_std_cast_object_tostring 找不到问题
#include
而不是
#include "zend_object_handlers.h"
http://cs.potsdam.edu/Documentation/php/html/zend-api.zend-std-cast-object-tostring.html
http://cs.potsdam.edu/Documentation/php/html/zend-api.zend-std-cast-object-tostring.html
类型转化问题
Z_OBJ_P(data)
将zval 转化成zend_object
https://learnku.com/articles/9173/2-analysis-of-zval
http://www.phpinternalsbook.com/php7/internal_types/zvals/basic_structure.html
https://yuerblog.cc/2017/08/09/course4-how-the-zval-works/
将zend_string转化成zval
zval myval;
zend_string *hello, *world;
zend_string_init(hello, “hello”, strlen(“hello”), 0);
/* 存储字符串到 zval */
ZVAL_STR(&myval, hello);
https://learnku.com/docs/php-internals/php7/strings_zend_strings/6852
将zval转化成zend_string
ZSTR_VAL(str));
http://www.phpinternalsbook.com/php7/internal_types/strings/zend_strings.html
https://xz.aliyun.com/t/5426
获取zval的值及类型
zval的类型通过Z_TYPE(zval)、Z_TYPE_P(zval*)两个宏获取,这个值取的就是zval.u1.v.type,但是设置时不要只修改这个type,而是要设置typeinfo,因为zval还有其它的标识需要设置,比如是否使用引用计数、是否可被垃圾回收、是否可被复制等等。
内核提供了Z_XXX(zval)、Z_XXX_P(zval*)系列的宏用于获取不同类型zval的value。
Z_LVAL(zval)、Z_LVAL_P(zval_p): 返回zend_long
Z_DVAL(zval)、Z_DVAL_P(zval_p): 返回double
Z_STR(zval)、Z_STR_P(zval_p): 返回zend_string*
Z_STRVAL(zval)、Z_STRVAL_P(zval_p): 返回char,即:zend_string->val
Z_STRLEN(zval)、Z_STRLEN_P(zval_p): 获取字符串长度
Z_STRHASH(zval)、Z_STRHASH_P(zval_p): 获取字符串的哈希值
Z_ARR(zval)、Z_ARR_P(zval_p)、Z_ARRVAL(zval)、Z_ARRVAL_P(zval_p): 返回zend_array
Z_OBJ(zval)、Z_OBJ_P(zval_p): 返回zend_object*
Z_OBJ_HT(zval)、Z_OBJ_HT_P(zval_p): 返回对象的zend_object_handlers,即zend_object->handlers
Z_OBJ_HANDLER(zval, hf)、Z_OBJ_HANDLER_P(zv_p, hf): 获取对象各操作的handler指针,hf为write_property、read_property等,注意:这个宏取到的为只读,不要试图修改这个值(如:Z_OBJ_HANDLER(obj, write_property) = xxx;),因为对象的handlers成员前加了const修饰符
Z_OBJCE(zval)、Z_OBJCE_P(zval_p): 返回对象的zend_class_entry*
Z_OBJPROP(zval)、Z_OBJPROP_P(zval_p): 获取对象的成员数组
Z_RES(zval)、Z_RES_P(zval_p): 返回zend_resource*
Z_RES_HANDLE(zval)、Z_RES_HANDLE_P(zval_p): 返回资源handle
Z_RES_TYPE(zval)、Z_RES_TYPE_P(zval_p): 返回资源type
Z_RES_VAL(zval)、Z_RES_VAL_P(zval_p): 返回资源ptr
Z_REF(zval)、Z_REF_P(zval_p): 返回zend_reference*
Z_REFVAL(zval)、Z_REFVAL_P(zval_p): 返回引用的zval*
https://juejin.im/entry/5a41fc8cf265da43305eb7e9
https://www.tuine.me/php7-internal/3/zend_runtime_cache.html
https://www.ucloud.cn/yun/29096.html
https://learnku.com/docs/php-internals/php7/building_php/6840
https://gywbd.github.io/posts/2016/2/debug-php-source-code.html
https://gywbd.github.io/posts/2016/4/php-new-syntax-feature.html
https://xz.aliyun.com/t/5201
https://www.ssfiction.com/archives/48519
https://github.com/phacility/xhprof/issues/89
$php -m |grep slow
PHP Warning: PHP Startup: slowLog: Unable to initialize module
Module compiled with module API=20160303
PHP compiled with module API=20190128
These options need to match
in Unknown on line 0
Warning: PHP Startup: slowLog: Unable to initialize module
make clean
phpize
./configure
make
make install
$php -m |grep slow
PHP Warning: Missing arginfo for confirm_slowLog_compiled() in Unknown on line 0
Warning: Missing arginfo for confirm_slowLog_compiled() in Unknown on line 0
slowLog
cd ext
$./ext_skel –extname=ext8
$./ext_skel –extname=ext_hello_world
https://www.php.net/manual/ru/internals2.buildsys.skeleton.php
/Users/didi/PhpstormProjects/c/php-src/ext/ext_hello_world/ext_hello_world.c:9:10: fatal error: ‘php_%EXT_HELLO_WORLD%.h’ file not found
#include “php_%EXT_HELLO_WORLD%.h”
^
2 errors generated.
make: *** [ext_hello_world.lo] Error 1
php8 去掉了bash脚本
用./ext_skel.php –extname=ext_hello_world
$./ext_skel.php –extname=ext_hello
PHP Warning: Missing arginfo for confirm_slowLog_compiled() in Unknown on line 0
Warning: Missing arginfo for confirm_slowLog_compiled() in Unknown on line 0
Error: Unsupported argument “–extname=ext_hello” passed
vi /usr/local/lib/php.ini
;extension=slowLog.so
https://github.com/php/php-src/blob/master/ext/ext_skel.php
$php ext_skel.php –extname=ext_hello
Error: Unsupported argument “–extname=ext_hello” passed
$php ext_skel.php –ext ext_hello
Copying config scripts… done
Copying sources… done
Copying tests… done
Success. The extension is now ready to be compiled. To do so, use the
following steps:
cd /path/to/php-src/ext/ext_hello
phpize
./configure
make
Don’t forget to run tests once the compilation is done:
make test
Thank you for using PHP!
$make install
Installing shared extensions: /usr/local/lib/php/extensions/debug-non-zts-20190128/