swoole / swoole-cli

SWOOLE-CLI is a php binary distribution composed swoole & php-core & cli & fpm and mostly of common extensions.
181 stars 33 forks source link

Warning: exec(): Unable to fork #675

Open niceboyat opened 2 weeks ago

niceboyat commented 2 weeks ago

win10下cmd运行: swoole-cli -f ./test.php

test.php文件代码: <?php exec('dir', $str, $code); ?>

出现这个错误:

Warning: exec(): Unable to fork [dir] in /usr/bin/test.php on line 1
jingjingxyk commented 2 weeks ago

错误提示产生的代码: https://github.com/swoole/swoole-cli/blob/bf6a2448fa421ed9dd661de17c83116fc5a2b973/ext/standard/exec.c#L136C3-L136C65

需要研究下

jingjingxyk commented 2 weeks ago

你试一下 shell_exec 是不是也不好使。 不添加 -f 参数也试试,是否也报错

jingjingxyk commented 2 weeks ago

本项目应该是没有定义 PHP_WIN32 , 因为 windows cygwin 环境下构建,其实是类 linux 环境构建, 这是完整构建配置: https://github.com/swoole/swoole-cli/blob/main/sapi/scripts/cygwin/cygwin-config.sh

windows 原生构建 ,定义 PHP_WIN32 所在文件: https://github.com/php/php-src/blob/php-8.1.27/win32/build/confutils.js#L3227

  1. linux 原生构建 执行的是 ./buildconf --force ,具体文件: https://github.com/php/php-src/blob/php-8.1.27/buildconf.bat
  2. windows 原生构建 执行的是 buildconf.bat --f , 具体文件: https://github.com/php/php-src/blob/php-8.1.27/buildconf.bat
jingjingxyk commented 2 weeks ago

windows 构建配置在这个目录: https://github.com/php/php-src/tree/php-8.1.27/win32/build

jingjingxyk commented 2 weeks ago

可定制一下编译参数试试,找到这个文件 https://github.com/swoole/swoole-cli/blob/main/sapi/scripts/cygwin/cygwin-config.sh

添加这一行


export CFLAGS="-DZEND_WIN32=1 "

类似这个,实验一下,看能否解决 image

实验pr : https://github.com/swoole/swoole-cli/pull/680/files

jingjingxyk commented 2 weeks ago

看 VCWD_POPEN 函数的定义: 位于 https://github.com/swoole/swoole-cli/tree/main/Zend/zend_virtual_cwd.h 文件

image

jingjingxyk commented 2 weeks ago

可实验添加的参数 参考: https://github.com/php/php-src/blob/php-8.1.27/win32/build/confutils.js#L3227


export CFLAGS="-DZEND_WIN32=1 -DPHP_WIN32=1 -DWIN32 "
jingjingxyk commented 2 weeks ago

查看编译结果: https://github.com/swoole/swoole-cli/actions/runs/9833711486/job/27144355874

jingjingxyk commented 2 weeks ago

windows版swoole-cli 函数shell_exec Unable to execute

jingjingxyk commented 2 weeks ago

@niceboyat 你试试 不添加 -f 执行,报错吗?