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

swoole http server, hook all之后,如果curl_file_create的文件是远程地址,上传报错 #5197

Closed
luolaifa000 opened this issue Nov 20, 2023 · 2 comments

Comments

@luolaifa000
Copy link
Contributor

swoole http server, hook all之后,curl_file_create的文件是远程地址,上传报错,原生是正常运行

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

$filePath = 'https://avatars.githubusercontent.com/u/8252640?v=4';

// 创建 CURLFile 对象
$file = curl_file_create($filePath);

// 创建 cURL 资源
$curl = curl_init();

// 设置 cURL 选项
curl_setopt($curl, CURLOPT_URL, 'http://example.com/upload.php');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, ['file' => $file]);

// 执行请求
$response = curl_exec($curl);

// 检查请求是否成功
if ($response === false) {
echo 'Error: ' . curl_error($curl);
} else {
echo 'File uploaded successfully.';
}

// 关闭 cURL 资源
curl_close($curl);

  1. What did you expect to see?
    我期望 协程场景下,支持上传远程地址文件路径,不用本地下载下来,多一个流程

  2. What did you see instead?

Swoole\Coroutine\Http\Client::addFile(): cannot send empty file[(null)],

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

Swoole => enabled
Version => 4.8.13

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?

Image: ubuntu-22.04
Version: 20231030.2.0

@luolaifa000
Copy link
Contributor Author

luolaifa000 commented Nov 20, 2023

看了Swoole\Coroutine\Http\Client::addFile()实现,确实有判断
if (stat(path, &file_stat) < 0) {
php_swoole_sys_error(E_WARNING, "stat(%s) failed", path);
RETURN_FALSE;
}
但是 stat只支持本地路径文件,导致报错,原生的curl_file_create最终使用php stream, 支持远程文件的

@matyhtf
Copy link
Member

matyhtf commented Nov 21, 2023

默认的模拟实现不支持远程文件,可改为使用 curl native

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

No branches or pull requests

2 participants