使用宝塔面板安装的php swoole6扩展,在自定义进程中使用协程,在协程中使用定时任务创建协程,在协程中使用GuzzleHttp上传文件报错
class VideoDownload1
{
public function onWorkerStart()
{
new Crontab('*/2 * * * * *', function () {
Coroutine::create(function(){
try {
$url = '';
$file=fopen($filePath, 'r');
if(!$file){
throw new \Exception('file not found');
}
$multipart = [
[
'name' => 'file',
'contents' => $file,
],
[
'name' => 'user_id',
'contents' => '1',
]
];
$client = new Client();
$client = $client->request('POST', $url, [
'headers' => [
'Token' => '',
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36',
],
'multipart' => $multipart,
'timeout' => 3000,
]);
$response = $client->getBody()->getContents();
$data = json_decode($response, true);
if ($data['status'] == 'Success') {
}
} catch (ClientException $th) {
throw new \Exception($th->getMessage(),$th->getCode());
}
});
});
}
}
cURL error 0: The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information. (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
return [
'VideoDownload' => [
'eventLoop' => Swoole::class,
'handler' => VideoDownload1::class,
'count'=>1
]
];
框架:Workerman/5.1.0 Webman/2.1
PHP:PHP/8.1.31 (Jit off)
Swoole:通过宝塔php扩展安装的swoole6
系统:CentOS 7.6.1810 x86_64
宝塔:9.4.0
使用curl访问baidu返回的结果是:“string(161) "<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>bfe/1.0.8.18</center>
</body>
</html>
"”
php --ri swoole 看看有没有curl-native,没有的话编译swoole的时候加个--enable-swoole-curl
确实是这个问题
已解决
问题的原因是CentOS7安装了swoole6的原因,在宝塔的安装脚本中判断了curl的版本,只有高于7560才会安装curl,CentOS7最高支持的curl版本是7290