我写了一个PHP脚本,使用ftp_put将目录中的图像上传到远程服务器。我已经使用任务调度程序和wget将其设置为cron。最初它运行良好,但过了一段时间,不知道该进程冻结的具体时间,由“Windows任务计划程序”说明它正在运行作业,但没有照片不再上传。长时间运行的php脚本作为cron失败
最初我以为问题是由于max_execution_time,但我已设置为24小时通过使用set_time_limit(3600 * 24);我已将max_input_time设置为600秒(10分钟)。
为什么不完成任务?
下面是代码:
if($conn){
if (is_dir($imagesPath)){
if($files = opendir($imagesPath)){
while(($file = readdir($files)) !== false){
if($file != "." && $file != ".." && preg_match("/\.jpg|\.JPG|\.gif|\.GIF|\.png|\.PNG|\.bmp|\.BMP/",$file) && date("Ymd",filemtime($imagesPath.'/'.$file)) >= date("Ymd",strtotime(date("Y-m-d")." -".$days." day"))){
if(ftp_put($conn, $remotePath.$file, $imagesPath.'/'.$file, FTP_BINARY)){
//echo $file;
$counter++;
}
else{
echo '<br>'.$imagesPath.'/'.$file;
}
}
}
closedir($files);
echo $counter.' Files Uploaded on '.date("Y-m-d");
}
else{
echo 'Unable to read '.$imagesPath;
}
}
else{
echo $imagesPath.' Does not exist';
}
ftp_close($conn);
}else{
echo "Failed to connect";
}
/* End */
exit;
补充:
/* Settings */
// Set Max Execution time
set_time_limit(3600*24);
在脚本的顶部。
谢谢。
你有没有检查日志?你有没有设置cron作业来保存输出到某个日志文件? –
没有看到代码,不可能说。让脚本在每个主要状态下吐出一些调试/日志记录语句,并查看锁定前的最后阶段。 –
尝试关闭任务并添加调试消息,以便您可以查看连接是否失败或上载等。 - 可能上传限制(允许的总存储空间)是否达到某个点? - 我想我们需要更多信息。 – Smamatti