swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.42k stars 3.16k forks source link

Is it possible to disable coroutine hooks automatically in spl_autoload_register? #3263

Closed Reasno closed 4 years ago

Reasno commented 4 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.

During autoloading, coroutines switches would lead to a fatal error. As hooks are defined globally while autoload functions are often registered in vendors, it is not easy to manually override autoload functions one by one. I would like to see Swoole disables runtime hooks automatically during autoloading to avoid surprises.

<?php
Co::set(['hook_flags'=> SWOOLE_HOOK_ALL]);
$load = function ($name) {
    sleep(1); // or file_get_content('path/to/source.php');
    eval('class InexistentClass{}');
};
spl_autoload_register($load);
Co\run(function () {
    go(function () {
        new InexistentClass;
    });
    go(function () {
        new InexistentClass;
    });
});
  1. What did you expect to see?

InexistentClass loaded.

  1. What did you see instead?

Fatal error: Uncaught Error: Class 'InexistentClass' not found in /test.php:13

  1. What version of Swoole are you using (show your php --ri swoole)?
swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.16
Built => Mar 14 2020 23:18:06
coroutine => enabled
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2s  28 May 2019
http2 => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777223/D16777223
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 262144 => 262144
  1. What is your machine environment used (including version of kernel & php & gcc) ?

不相关。

twose commented 4 years ago

[自动回复] 为了Github社区各国友人的参与理解和问题的存档检索所需,本repo只接受英文issue

中文issue请前往Swoole中文问答社区

谢谢合作!