我有一个服务器长时间运行的应用程序存储过程像这样:
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));
尝试在后台进程中运行此代码,如异步队列或crons
while($s = fgets($pipes[2])) { if(strpos($s,"Progress:") !== FALSE) { Log::info(100 * substr($s,4) . '%'); $this->redis->SET('sliceProgress' . $uid,4) . '%'); } }
原文地址:https://www.jb51.cc/php/140228.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。