linux瀹氭椂浠诲姟鎵цphp鑴氭湰鍒犻櫎鏂囦欢

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux瀹氭椂浠诲姟鎵цphp鑴氭湰鍒犻櫎鏂囦欢相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/note' title='note'>note   read   鏃堕棿   鎵撳紑   clean   PHP浠g爜   鍒楄〃   plugin   efi   

php浠g爜

// 瑕佸垹闄ょ殑鏂囦欢璺緞
$path = __DIR__ . "/runtime/temp_img/";

// 瀹氫箟瑕佸垹闄ょ殑鏃堕棿闂撮殧锛氫竷澶?/span>
$weekSecond = 7 * 24 * 3600;

$num = 0;
if (is_dir($path)) {
    // 鑾峰彇鐩綍鍙ユ焺
    $handle = opendir($path);
    // 寰幆璇诲彇鍑烘枃浠?/span>
    while ($temp = readdir($handle)) {
        // 蹇界暐绯荤粺鏂囦欢
        if ($temp == 鈥?鈥?|| $temp == 鈥?.鈥?span style="color: #000000;">) {
            continue;
        }
        // 鑾峰彇鏂囦欢淇℃伅
        $info = stat($path . $temp);
        if ((time() - $info[鈥榤time鈥榏) > $weekSecond) {
            // 鍒犻櫎瓒呰繃涓冨ぉ鏈慨鏀硅繃鐨勬枃浠?/span>
            unlink($path . $temp);
            $num++;
        }
    }
    // 鍏抽棴鍙ユ焺
    closedir($handle);
}

// 鍐欐棩蹇?/span>
echo date(鈥榊-m-d H:i:s鈥? time()) . 鈥?clean up file number: 鈥?. $num . "
";

 

 linux鍛戒护

# 鎵撳紑瀹氭椂浠诲姟缂栬緫鍒楄〃鏂囦欢锛?br />crontab -e

# 娣诲姞浠ヤ笅浠诲姟锛岀劧鍚庝繚瀛樺嵆鍙敓鏁?br />0 22 * * * /usr/local/php-5.6.26/bin/php /usr/local/apache/htdocs/ClientPortalRebuild/cp/pluginPortal/deleteFile.php 2>&1 1>> /usr/local/apache/htdocs/ClientPortalRebuild/cp/pluginPortal/log/log.log

鎶€鏈浘鐗? src=

 璇存槑锛?/p>

1. * 22 * * *   # 姣忓ぉ22鐐规墽琛岃剼鏈?/span>

2. /usr/local/php-5.6.26/bin/php # php鍚姩鍣?/span>

3. /usr/local/apache/htdocs/ClientPortalRebuild/cp/pluginPortal/deleteFile.php # 瑕佹墽琛岀殑php鑴氭湰

4. 2>&1 # 2鏄敊璇俊鎭紝1鏄纭俊鎭紝鍔犺捣鏉ュ氨鏄纭殑鍜岄敊璇殑淇℃伅

5. 1>> /usr/local/apache/htdocs/ClientPortalRebuild/cp/pluginPortal/log/log.log # 鍦ㄧ4鐐硅瀹氱殑淇℃伅缁熶竴鍐欏埌杩欎釜璺緞涓嬬殑鏃ュ織鏂囦欢涓?/span>

 

鑷虫鎼炲畾~~

闄勪笂crontab浠诲姟鍛戒护璇存槑閾炬帴锛?a href="https://www.runoob.com/w3cnote/linux-crontab-tasks.html">https://www.runoob.com/w3cnote/linux-crontab-tasks.html

以上是关于linux瀹氭椂浠诲姟鎵цphp鑴氭湰鍒犻櫎鏂囦欢的主要内容,如果未能解决你的问题,请参考以下文章

08.@Scheduled瀹氭椂浠诲姟銆佹暣鍚坖dbcTemplate銆乵ybatis鍖哄垎澶氭暟鎹簮

鍦∕ac涓嬩娇鐢╟rontab鎵ц瀹氭椂鑴氭湰

php瓒呮椂浠诲姟澶勭悊

Oracle寤鸿〃鑴氭湰璁板綍

jenkins鎵ц鑴氭湰npm: command not found瑙e喅

os妯″潡