我们有一个PHP项目,用户上传文件,软件启动加密该文件的过程。
加密过程大约需要5-7分钟。
但是当加密过程进行时,在另一个用户之间上传文件。然后我们的流程停止并再次启动流程。
为了解决这个问题,我们制作了一个进程表,其中新文件的文件路径以FIFO方式存储,但是当添加新文件时,进程再次启动。
应该做什么,流程不会停止,文件应该等待轮到?
$sql="SELECT * FROM tbl_process";
$result = mysqli_query($con,$sql);
$countforh = mysqli_num_rows($result);
for($h = 1; $h<=$countforh; $h++)
{
$sql="SELECT * FROM tbl_process WHERE (sr_no = '".$h."' AND com_status = '0')";
//Con_status = 0 is for the file which is not encrypted.
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
if (is_null($row['pfile_path']))
{
continue; //if Con_status = 1
}
$sql="SELECT * FROM tbl_process WHERE (sr_no = '".$h."' AND com_status = '0')";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
{
$_SESSION['filepath'] = $row['pfile_path'];
$_SESSION['upload_tbl_sr'] = $row['upload_sr_no'];
}
现在我们开始加密过程。
答案 0 :(得分:1)
您可以使用会话或序列化文件来标记或上传文件。
PHP将文件导入系统后,即可开始录制文件或会话
//File serialized, to First file
if($_FILES['file']['error'] != 0){ //Checks for error while importing file
if (!file_exists($tmpF)) {
$count = 1;
$queue[] = ['id'=>$count,'nameFile'=>$_FILES['file']['name'],'status'=>0];
$tmpF = sys_get_temp_dir().'/reportUpload.txt';
$tmp = fopen($tmpF,'w');
fwrite($tmp, serialize($queue));
fclose($tmp);
}else{
//For the second file on.
$tmpF = sys_get_temp_dir().'/reportUpload.txt';
$file = fopen($tmpF,'r');
$queue = unserialize(fgets($file));
fclose($file);
$last = count($queue);
$count = $queue[$last]['id']+1;
$queue[] = ['id'=>$count,'nameFile'=>$_FILES['file']['name'],'status'=>0];
$tmp = fopen($tmpF,'w');
fwrite($tmp, serialize($queue));
fclose($tmp);
}
}
//Starting Encryption
$tmpU = sys_get_temp_dir().'/reportUploadExecution.txt';
if(!file_exists($tmpU)){
$tmpF = sys_get_temp_dir().'/reportUpload.txt';
$file = fopen($tmpF,'r');
$queue = unserialize(fgets($file));
$line = 0;
while(!feof($queue)){
if($queue[$line]['status']==FALSE){
//Starting Encryption
$tmpU = sys_get_temp_dir().'/reportUploadExecution.txt';
$execution = ['id'=>$line,'nameFile'=>$queue[$line]['nameFile']]
$tmp1 = fopen($tmpU,'w');
fwrite($tmp1, serialize($execution));
fclose($tmp1);
// Your code here
// If encryption ended successfully set line "Status" = 1
unlink($tmpU);
$line++;
}
}
fclose($file);
}
这只是一个想法,如果您可以发布部分代码,它会更好地帮助您。