我有一个长时间运行的服务器应用程序,它存储这样的进程:
routes.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))));
}
and$interval(function()
{
$scope.refreshProgress();
}, 500);
但是客户端的进度请求会一直保持到100%结束,没有不到100%的进度。也就是说,当服务器分片应用程序完成时,我才获得进度响应。我认为,当Laravel处理分片时,它不会处理第二个请求。
编辑: 在redis->SET正常工作后,我使用以下代码在slice()中获取redis,这将实时输出sliceProgress。
Log::info($this->redis->GET('sliceProgress' . $uid));