swoole / swoole-src

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

为什么swow可以pcntl_fork,swoole不行? #4945

Closed he426100 closed 1 year ago

he426100 commented 1 year ago

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error. 做了个小的命令行程序,引入了psy/psysh,发现跟swoole有冲突,如果用\Swoole\Coroutine\run包裹入口的话psysh用不了,会提示pcntl_fork() has been disabled

  2. What did you expect to see? 期望像swow下那样正常使用

  3. What did you see instead? pcntl_fork() has been disabled

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

    
    swoole

Swoole => enabled Author => Swoole Team team@swoole.com Version => 5.0.1 Built => Nov 8 2022 11:11:46 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.1.1m 14 Dec 2021 dtls => enabled http2 => enabled json => enabled curl-native => enabled c-ares => 1.18.1 zlib => 1.2.11 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled 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 => On => On swoole.unixsock_buffer_size => 8388608 => 8388608



5. What is your machine environment used (show your `uname -a` & `php -v` & `gcc -v`) ?
`Linux mrpzx 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux`
`Swoole 5.0.1 (cli) (built: Nov  8 2022 11:12:59) (NTS)`
NathanFreeman commented 1 year ago

因为fork一个多线程结果是不安全的

twose commented 1 year ago

因为libuv支持fork,但也是实验性的,只能覆盖一般的fork情况,建议用proc_open来开启和管理新的进程。

he426100 commented 1 year ago

因为libuv支持fork,但也是实验性的,只能覆盖一般的fork情况,建议用proc_open来开启和管理新的进程。

好的,感谢解答