Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register_shutdown_function() 触发时机疑问 #2144

Closed
Yurunsoft opened this issue Nov 23, 2018 · 2 comments
Closed

register_shutdown_function() 触发时机疑问 #2144

Yurunsoft opened this issue Nov 23, 2018 · 2 comments

Comments

@Yurunsoft
Copy link
Member

代码:

<?php

use Swoole\Coroutine;

function test()
{
    Coroutine::sleep(1);
    var_dump('test gg');
}

register_shutdown_function(function(){
    var_dump('all gg');
});

go('test');

输出:

string(6) "all gg"
string(7) "test gg"

我认为的正常的结果应该是协程里面的执行完,再触发register_shutdown_function吧?不知道是有意如此,还是bug

@matyhtf
Copy link
Member

matyhtf commented Nov 24, 2018

如果你的脚本末尾没有swoole_event_wait(),底层会将swoole_event_wait()注册register_shutdown_function,执行顺序就会变成上面的。

请在代码末尾加入 swoole_event_wait();

@twose
Copy link
Member

twose commented Nov 26, 2018

@Yurunsoft
现在swoole_event_wait永远都是第一位, 结果符合预期

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants