약간의 손실이 있습니다. 메일 함에서 전자 메일 첨부 파일을 가져 오는 두 개의 스크립트 1과 첨부 파일을 구문 분석하여 DB에 추가하는 두 번째 스크립트가 있습니다.파일 쓰기 충돌 : file_get_contents() & fputs()
이것은 대부분 시간에 문제가 없지만 몇 가지 문제가 다시 발생합니다. 전자 메일 첨부 파일이 만들어 지지만 채워지지 않은 경우 (이름을 제외한 빈 파일) 가끔 생성 (다운로드)되지 않는 경우가 있습니다.
첫 번째 스크립트는 새 파일을 열고 그 파일에 쓰고 두 번째 스크립트는 해당 파일의 내용에 액세스합니다. 두 번째 스크립트가 파일에 액세스하려고 시도 할 때 파일이 열려 있기 때문에 이러한 문제가 발생할 수 있습니까?
15 초마다 번갈아 실행됩니다.
1 스크립트가 (그 꽤 큰이 그래서 난 그냥 문제의 부분을 보여주기 위해 시도)
for ($jk = 1; $jk <= imap_num_msg($mbox); $jk++) {
echo "~~~~~~~~~~~~~~BEGIN!~~~~~~~~~~~~~~~~~~\n";
echo imap_num_msg($mbox);
$structure = imap_fetchstructure($mbox,$jk); echo "imap_fetchstructure()\n";
$parts = $structure->parts; echo "structure->parts\n";
$fpos=2;
for($i = 1; $i < count($parts); $i++) { echo "loop through parts of email\n";
$message["pid"][$i] = ($i);
$part = $parts[$i];
if($part->disposition == "ATTACHMENT") { echo "if ATTACHMENT exists then grab data from it\n";
$message["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype);
$message["subtype"][$i] = strtolower($part->subtype);
$ext=$part->subtype;
$params = $part->dparameters;
$filename=$part->dparameters[0]->value;
$num = $this->append();
$newFilename = $this->addToDB($filename,$num);
echo $newFilename."- Added tp DB\n";
$mege="";
$data="";
$mege = imap_fetchbody($mbox,$jk,$fpos);
$filename="$newFilename";
$fp=fopen($savedirpath.$filename,w); echo "Create file at specified location\n";
$data=$this->getdecodevalue($mege,$part->type);
fputs($fp,$data); echo "Write data to the file\n";
echo ">>>>>>>>>>>>> File ".$savedirpath.$newFilename." ~ now exists!\n";
fclose($fp);
$fpos+=1;
imap_mail_move($mbox,'1:1','Processed');
echo "****************************************************\n";
echo "* Matched - Download and move to Processed folder. *\n";
echo "****************************************************\n";
echo "\n\n\n";
}
}
}
}else{
imap_mail_move($mbox,'1:1','Other');
echo "***************************************************\n";
echo "******** No Match - Move to Other folder **********\n";
echo "***************************************************\n";
}
imap_close($mbox);
}
제 2 스크립트 파일 이름을 복용하여 분석 한 무리가 1 스크립트에서 DB에 추가하지, 다음과 같이 붙이십시오.
$addXML = "<xml>".file_get_contents($filename)."</xml>";
$tickets = simplexml_load_string($addXML);