我有一个服务器长时间运行的应用程序存储过程像这样:
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,4) . '%');
}
}
和我的客户每0.5秒请求重新进行的这个:
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%的进度.也就是说,当服务器切片应用程序完成时,我得到进度响应.我想Lailavel在处理片时不处理第二个请求.
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));