Windows Server + IIS + PHP(CGI 模式),需每小時執行一次掃描腳本。
假設 PHP 安裝於 D:\php,腳本位於 D:\wwwroot\dingshi.php:
@echo off
D:
cd \php
php.exe D:\wwwroot\dingshi.php
儲存為 test.bat。
雙擊 test.bat,檢查 dingshi.php 邏輯是否執行(例如寫入檔案):
<?php
file_put_contents("a.php", "test");
?>
若 a.php 內容為 test 代表批次檔正常。
PHP_定時掃描,描述自填 → 下一步。D:\php\test.bat(批次檔完整路徑),引數留空 → 下一步。排程器將每天在設定開始時間起,每小時執行一次 test.bat,進而呼叫 php.exe dingshi.php,達成每小時定時掃描。
> D:\logs\dingshi.log 2>&1 導向輸出日誌,便於除錯。php-cgi.exe 或設定環境變數後直接用 php。crontab,更簡單彈性。