我寫了一個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