We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
//需要开启协程数、判断需要处理的图片数与协程数,取较小值 $loopSize = $size < ($imageLength-$start) ? $size : ($imageLength-$start); for ($j = 0; $j < $loopSize; $j++){ //保存图片 $wg->add(); go (function () use($wg, $redis, $j, $start, $imageLocalPath, $channel, $imageUrl, $imagePath, $exportId){ $imageIndex = $j + $start; $image_url = $imageUrl[$imageIndex]; if (empty($image_url) || $image_url == "") { $imageData = [$imageIndex=>""]; $channel->push($imageData); }else { $client = new HttpClient(); $endWith = pathinfo($image_url); $endType = "jpg"; if (isset($endWith['extension'])) { $endType = $endWith['extension']; } $client->setUrl($image_url); $client->setTimeout(15); $filename = "{$imagePath}/{$imageIndex}.{$endType}"; $imageLocalFullPath = "{$imageLocalPath}/{$imageIndex}.{$endType}"; $imageData = [$imageIndex=>$imageLocalFullPath]; $channel->push($imageData); try { $res = $client->download($filename, 0, HttpClient::METHOD_GET, $client->get()->getBody()); Manager::getInstance()->get("ssc_capture")->invoke(function (Redis $redis) use ($exportId) { $redis->hIncrBy($this->taskId, "handle_num", 1); }); $client->getClient()->close(); } catch (\Exception $e) { echo CLASS."".FUNCTION.""."下载图片异常_".$e->getMessage().PHP_EOL; } } $wg->done(); }); } $wg->wait(); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
//需要开启协程数、判断需要处理的图片数与协程数,取较小值
$loopSize = $size < ($imageLength-$start) ? $size : ($imageLength-$start);
for ($j = 0; $j < $loopSize; $j++){
//保存图片
$wg->add();
go (function () use($wg, $redis, $j, $start, $imageLocalPath, $channel, $imageUrl, $imagePath, $exportId){
$imageIndex = $j + $start;
$image_url = $imageUrl[$imageIndex];
if (empty($image_url) || $image_url == "") {
$imageData = [$imageIndex=>""];
$channel->push($imageData);
}else {
$client = new HttpClient();
$endWith = pathinfo($image_url);
$endType = "jpg";
if (isset($endWith['extension'])) {
$endType = $endWith['extension'];
}
$client->setUrl($image_url);
$client->setTimeout(15);
$filename = "{$imagePath}/{$imageIndex}.{$endType}";
$imageLocalFullPath = "{$imageLocalPath}/{$imageIndex}.{$endType}";
$imageData = [$imageIndex=>$imageLocalFullPath];
$channel->push($imageData);
try {
$res = $client->download($filename, 0, HttpClient::METHOD_GET, $client->get()->getBody());
Manager::getInstance()->get("ssc_capture")->invoke(function (Redis $redis) use ($exportId) {
$redis->hIncrBy($this->taskId, "handle_num", 1);
});
$client->getClient()->close();
} catch (\Exception $e) {
echo CLASS."".FUNCTION.""."下载图片异常_".$e->getMessage().PHP_EOL;
}
}
$wg->done();
});
}
$wg->wait();
}
The text was updated successfully, but these errors were encountered: