GithubHelp home page GithubHelp logo

php-extension-research / study Goto Github PK

View Code? Open in Web Editor NEW
348.0 18.0 76.0 389 KB

手把手教你写PHP协程扩展(teach you to write php coroutine extension by hand)

Home Page: https://php-extension-research.github.io/study/#/

M4 3.56% Shell 0.26% C 8.64% PHP 3.88% C++ 82.86% Dockerfile 0.81%
php7 php php-extension c-plus-plus coroutine

study's People

Contributors

colorrabbit avatar her-cat avatar huanghantao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

study's Issues

未定义变量:undefined symbol: _ZN3Lib12PHPCoroutine6createEP22_zend_fcall_info_cachejP12_zval_struct

long PHPCoroutine::create(zend_fcall_info_cache *fci_cache, uint32_t argc, zval *argv)
{
    php_coro_args php_coro_args;
    php_coro_args.fci_cache = fci_cache;
    php_coro_args.argv = argv;
    php_coro_args.argc = argc;
    save_task(get_task());

    return Coroutine::create(create_func, (void*) &php_coro_args);
}

好像是这里报错,提示zend_fcall_info_cache 未定义么? 这不是php自定义的宏么,我已经引入了php.h 了的

未正确维护closures object引用计数导致core dumped

问题描述
协程创建传入的闭包op_array分配在closures object成员属性,当yield后会被以参数释减少引用计数,
resume后closures object已被释放,将高概率性触发core dumped。
协程execute_data分配阶段应该手动对closures增加一次引用计数

以下是错误bt
Starting program: /usr/local/php7.3/bin/php -dextension=/usr/local/php7.3/lib/php/extensions/debug-non-zts-20180731/study.so -f /vagrant/www/tests/coroutine/bug.php [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". int(0) int(1) int(0) int(1) string(9) "cid_a_end" Program received signal SIGSEGV, Segmentation fault. 0x00000000009cb10c in zend_gc_delref (p=0x3) at /vagrant/www/php-src-win/Zend/zend_types.h:996 996 return --(p->refcount); (gdb) bt #0 0x00000000009cb10c in zend_gc_delref (p=0x3) at /vagrant/www/php-src-win/Zend/zend_types.h:996 #1 0x00000000009d310b in i_free_compiled_variables (execute_data=0x7ffff3e7b070) at /vagrant/www/php-src-win/Zend/zend_execute.c:2361 #2 0x00000000009d6260 in zend_leave_helper_SPEC () at /vagrant/www/php-src-win/Zend/zend_vm_execute.h:641 #3 0x00000000009dc2bb in ZEND_RETURN_SPEC_CONST_HANDLER () at /vagrant/www/php-src-win/Zend/zend_vm_execute.h:2808 #4 0x00000000009d5a8d in execute_ex (ex=0x7ffff3e7b070) at /vagrant/www/php-src-win/Zend/zend_vm_execute.h:43

以下是复现代码
`<?php
study_event_init();
$cid_a = Sgo(function () {
$b = function () {
$arr = debug_backtrace();
};
for($i=0;$i<=2;$i++){
Study\Coroutine::yield();
$arr =range(1,100002);
$b();
}
var_dump("cid_a_end");
});

$cid_b = Sgo(function () {
$b = function (){
$arr = debug_backtrace();
};

for($i=0;$i<=2;$i++){
    Study\Coroutine::yield();
    $arr =range(1,100001);
    $b();
}
var_dump("cid_b_end");

});

$count = 0 ;
$i= 0;
while ($count<=4){
if($i>1){
$i=0;
}
Study\Coroutine::resume($i==0?$cid_a:$cid_b);
var_dump($i);
$i++;
$count++;
}
study_event_wait();`

编译通过,但加载失败 提示:undefined symbol

报错提示:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20180731/lib.so' 
(tried: /usr/lib/php/20180731/lib.so (/usr/lib/php/20180731/lib.so:
 undefined symbol: _ZN3Lib9Coroutine10coroutinesE), 
/usr/lib/php/20180731//usr/lib/php/20180731/lib.so.so 
(/usr/lib/php/20180731//usr/lib/php/20180731/lib.so.so: cannot open shared object file:
 No such file or directory)) in Unknown on line 0

关键字:

undefined symbol: _ZN3Lib9Coroutine10coroutinesE)

分析原因

提示有看到`Lib`  `Coroutine` `coroutines` 这三个关键字,说明这里有问题,经排查:未初始化这个静态变量

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.