首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
PHP-8.4.6 + swoole-6.0.2 运行多线程出错
shuyinglee@x201:~$ php swoole.thread.php ``` NULL PHP Fatal error: Uncaught Error: Call to undefined method Swoole\Thread::exec() in /home/shuyinglee/swoole.thread.php:10 Stack trace: #0 {main} thrown in /home/shuyinglee/swoole.thread.php on line 10 ``` shuyinglee@x201:~$ cat php swoole.thread.php ``` <?php use Swoole\Thread; $args = Thread::getArguments(); $c = 4; var_dump($args); if (empty($args)) { for ($i = 0; $i < $c; $i++) { $threads[] = Thread::exec(__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/'); } } ``` shuyinglee@x201:~$ php -v ``` PHP 8.4.6 (cli) (built: May 28 2025 11:00:16) (ZTS) Copyright (c) The PHP Group Zend Engine v4.4.6, Copyright (c) Zend Technologies ``` shuyinglee@x201:~$ php --ri swoole ``` swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 6.0.2 Built => May 28 2025 13:39:29 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled thread => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 3.2.4 11 Feb 2025 dtls => enabled http2 => enabled json => enabled curl-native => enabled curl-version => 8.11.1 zlib => 1.3.1.zlib-ng brotli => E16781312/D16781312 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled Directive => Local Value => Master Value swoole.enable_library => On => On swoole.enable_fiber_mock => Off => Off swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ``` shuyinglee@x201:~$
发布于1年前 · 0 次浏览 · 来自
提问
李淑颖
shuyinglee@x201:~$ php swoole.thread.php ``` NULL PHP Fatal error: Uncaught Error: Call to undefined method Swoole\Thread::exec() in /home/shuyinglee/swoole.thread.php:10 Stack trace: #0 {main} thrown in /home/shuyinglee/swoole.thread.php on line 10 ``` shuyinglee@x201:~$ cat php swoole.thread.php ``` <?php use Swoole\Thread; $args = Thread::getArguments(); $c = 4; var_dump($args); if (empty($args)) { for ($i = 0; $i < $c; $i++) { $threads[] = Thread::exec(__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/'); } } ``` shuyinglee@x201:~$ php -v ``` PHP 8.4.6 (cli) (built: May 28 2025 11:00:16) (ZTS) Copyright (c) The PHP Group Zend Engine v4.4.6, Copyright (c) Zend Technologies ``` shuyinglee@x201:~$ php --ri swoole ``` swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 6.0.2 Built => May 28 2025 13:39:29 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled thread => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 3.2.4 11 Feb 2025 dtls => enabled http2 => enabled json => enabled curl-native => enabled curl-version => 8.11.1 zlib => 1.3.1.zlib-ng brotli => E16781312/D16781312 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled Directive => Local Value => Master Value swoole.enable_library => On => On swoole.enable_fiber_mock => Off => Off swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ``` shuyinglee@x201:~$
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2025-06-08
加了糖的格温
php要是zts模型和编译swoole要开启--enable-swoole-thread
赞
0
回复
2025-08-15
Rango-H
正式发布的版本创建线程的写法是: ```php $thread = new Swoole\Thread("/path/to/your_script.php"); ``` `Thread::exec()` 是一个中间版本的`API`设定,正式发版前被修改了。
赞
0
回复