网络定时问题导致PHP抛出“无法打开流:没有这样的文件或目录”
我们有三个邮件服务器,上面运行着PHP邮件应用程序。我们在一个单独的服务器上运行一个.NET作业,该服务器从facebook上传联系人照片,将其存储在NAS上的一个临时位置,然后调用PHP mail应用程序,告诉它将图像从临时位置移动到联系人记录中 这项工作,并没有代码的变化,工作得很好,我们只有一个邮件服务器,临时文件存储在本地。现在我们转到负载平衡配置,将临时文件放在NAS机箱上,这就存在wierd计时问题 在我们的.NET应用程序中,下载照片后,在将请求发送到邮件应用程序之前,我们会获取一个FileInfo对象,并检查该文件是否存在,只是为了确定。然后我们将请求发送到PHP,PHP现在间歇性地抛出:未能打开流:没有这样的文件或目录 但是,如果在检查.NET中是否存在fi.之后,在将请求发送到PHP之前,我们加入了一个Thread.Sleepn,那么错误就会减少。睡眠时间越长,PHP表示文件不存在的频率就越低 所以这个文件是存在的,但是出于某种原因,如果我们在下载后很快就试图访问它,PHP会认为它不存在 代码包括检查文件是否已完全下载且未标记为只读 你知道是什么导致了这个问题吗网络定时问题导致PHP抛出“无法打开流:没有这样的文件或目录”,php,.net,file-upload,Php,.net,File Upload,我们有三个邮件服务器,上面运行着PHP邮件应用程序。我们在一个单独的服务器上运行一个.NET作业,该服务器从facebook上传联系人照片,将其存储在NAS上的一个临时位置,然后调用PHP mail应用程序,告诉它将图像从临时位置移动到联系人记录中 这项工作,并没有代码的变化,工作得很好,我们只有一个邮件服务器,临时文件存储在本地。现在我们转到负载平衡配置,将临时文件放在NAS机箱上,这就存在wierd计时问题 在我们的.NET应用程序中,下载照片后,在将请求发送到邮件应用程序之前,我们会获取一
public void Save(string tempPath, string username, string password, bool deleteSrc, string merakController = "", string fileNamePrefix = "")
{
FileInfo fi = new FileInfo(tempPath);
if (fi.Exists)
{
Name = (fileNamePrefix ?? string.Empty) + fi.Name;
FileSize = fi.Length;
TimeStamp = fi.LastWriteTimeUtc;
string path = fi.FullName;
if (string.IsNullOrEmpty(Type))
throw new Exception("Attachment Type not set");
IceWarpGroupware_Http gwh = new IceWarpGroupware_Http(username, password);
string parameters = string.Format("AttName={0}&AttType={1}&AttDesc={0}&AttSize={2}&AttTime={3}", Name, Type, FileSize, Time);
fi.Refresh();
if (fi.Length != FileSize)
throw new Exception("It was still downloading?");//this has never been thrown, so thats not it
if (fi.IsReadOnly)
throw new Exception("read only"); //again, never hit, so thats not it
//adding this line makes it work 100% of the time -- reducing the sleep time makes it start to throw "failed to open stream: No such file or directory" intermittently
System.Threading.Thread.Sleep(15000);
bool result = gwh.AddAttachment(m_oid, path, parameters, string.Empty, merakController);
if (!result)
throw new Exception("Unable to add attachment \"" + Name + "\"");
try
{
if (deleteSrc)
fi.Delete();
}
catch { }
}
//else
// throw new Exception("Temp file not found");
}