WorkerMan升級(jí)到4.0后curl上傳文件出現(xiàn)異常CURLE_ABORTED_BY_CALLBACK。
Swoole的HTTP服務(wù)和FPM下正常。
請(qǐng)教如何解決?
<?php
use Workerman\Worker;
require_once __DIR__ . '/Workerman/Autoloader.php';
$http_worker = new Worker("http://0.0.0.0:2345");
$http_worker->count = 1;
$http_worker->onMessage = function ($connection, $reqest) {
$file = $reqest->file('file');
$path = __DIR__ . '/1.png';
copy($file['tmp_name'], $path);
$body = [
'file' => curl_file_create($path)
];
$content = curl_post('http://127.0.0.1:8080/api/api/imgupload', $body);
$connection->send($content);
};
function curl_post($url, $body)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$content = curl_exec($curl);
curl_close($curl);
return $content;
}
Worker::runAll();
這么寫的話沒測出問題,但我用的TP(5.1)框架,workerman的$request->file()賦值給了tp的$request->withFiles(),并在控制層調(diào)用Filesystem->writeStream寫文件到新目錄下,且調(diào)試發(fā)現(xiàn)文件已經(jīng)寫入成功,然后curl在提交直接CURLE_ABORTED_BY_CALLBACK了,不知道如何排查。
百度和google也沒搜到相關(guān)解決方案,CURLE_ABORTED_BY_CALLBACK這個(gè)異常一般是什么導(dǎo)致的?