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

跑示例报错:Class "Swoole\Thread" not found #160

Open
buexplain opened this issue Jul 6, 2024 · 2 comments
Open

跑示例报错:Class "Swoole\Thread" not found #160

buexplain opened this issue Jul 6, 2024 · 2 comments

Comments

@buexplain
Copy link

测试代码:

<?php

use Swoole\Thread;

require_once __DIR__ . '/vendor/autoload.php';

$args = Thread::getArguments(); // 如果是主线程,$args 为空,如果是子线程,$args 不为空

if (empty($args)) {
    # 主线程
    for ($i = 0; $i < $c; $i++) {
        $threads[] = new Thread(__FILE__, $i);
    }
    for ($i = 0; $i < $c; $i++) {
        $threads[$i]->join();
    }
} else {
    # 子线程
    echo "Thread #" . $args[0] . "\n";
    while (1) {
        sleep(1);
        file_get_contents('https://www.baidu.com/');
    }
}

错误:

D:\Code\test-swoolev6>D:\swoole-cli\v6.0.0\bin\swoole-cli.exe -v
Swoole 6.0.0-dev (cli) (built: Jul  5 2024 18:57:44) (NTS)

D:\Code\test-swoolev6>D:\swoole-cli\v6.0.0\bin\swoole-cli.exe test.php

Fatal error: Uncaught Error: Class "Swoole\Thread" not found in /cygdrive/d/Code/test-swoolev6/test.php:7
Stack trace:
#0 {main}
  thrown in /cygdrive/d/Code/test-swoolev6/test.php on line 7
@jingjingxyk
Copy link
Owner

jingjingxyk commented Jul 6, 2024

我找到问题在哪里了,缺少这两参数 --enable-swoole-thread --enable-zts ,编译时没有启用 thread
https://github.com/jingjingxyk/swoole-cli/blob/feature-swoole-v6/sapi/scripts/cygwin/cygwin-config.sh#L52
这个构建参数忘了改了,我改完,重新发一版

D:\swoole-cli\v6.0.0\bin\swoole-cli.exe --ri swoole 

@jingjingxyk
Copy link
Owner

jingjingxyk commented Jul 7, 2024

cygwin 编译环境下,编译报错
https://github.com/swoole/swoole-cli/actions/runs/9820930458/job/27116037763

报错信息:
TSRM/TSRM.o: in function tsrm_get_ls_cache_tcb_offset': /cygdrive/d/a/swoole-cli/swoole-cli/TSRM/TSRM.c:735:(.text+0xc13): undefined reference to _tsrm_ls_cache@gottpoff'

参考文档:
https://wiki.php.net/zts-improvement
https://github.com/php/php-src/blame/PHP-8.1.27/TSRM/TSRM.c#L769
https://github.com/swoole/swoole-cli/blob/main/TSRM/TSRM.c#L735

发现: 官方源码里 TSRM/TSRM.c 和 swoole-li 源码里 TSRM/TSRM.c 文件不太一样

待解决

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

No branches or pull requests

2 participants