gpt4 book ai didi

php - 无法实时从redis读取

转载 作者:IT王子 更新时间:2023-10-29 05:55:35 24 4
gpt4 key购买 nike

我有一个服务器长时间运行的应用程序,它存储这样的过程:

路由.php

Route::post('cloud/slice/{modelfileid}', 'CloudController@slice');
Route::get('cloud/slice/sliceProgress', 'CloudController@sliceProgress');

部分 slice() 函数:

while($s = fgets($pipes[2]))
{
if(strpos($s, "Progress:") !== FALSE)
{
Log::info(100 * substr($s, -10, 4) . '%');
$this->redis->SET('sliceProgress' . $uid, 100 * substr($s, -10, 4) . '%');

}
}

我的客户每 0.5 秒请求 redis 中的进度:

public function sliceProgress()
{
if (!isset($_SESSION["uid"]))
return Redirect::to('cloud');
$uid = $_SESSION["uid"];
return Response::json(array('status' => 'success', 'data' => array('progress' => $this->redis->GET('sliceProgress' . $uid))));
}

$interval(function()
{
$scope.refreshProgress();
}, 500);

但是客户端获取进度请求会一直保持到100%结束,没有小于100%的进度。也就是说,当服务器切片应用程序完成时,我得到了进度响应。我想 laravel 在处理切片时不会处理第二个请求。


Edited: I use below code to get the redis in the slice() after the redis->SET works well, this output the sliceProgress realtime.

Log::info($this->redis->GET('sliceProgress' . $uid));

最佳答案

尝试在异步队列或 crons 等后台进程中运行此代码

while($s = fgets($pipes[2]))
{
if(strpos($s, "Progress:") !== FALSE)
{
Log::info(100 * substr($s, -10, 4) . '%');
$this->redis->SET('sliceProgress' . $uid, 100 * substr($s, -10, 4) . '%');

}
}

关于php - 无法实时从redis读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41254473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com