cron은 정기적으로 실행되는 스크립트에 적합하지만 특정 시간에 일회성 (또는 2 회성) 스크립트를 실행하려면 unix 'at'명령을 사용하면됩니다. 그것은 바로 다음과 같은 코드를 사용하여 PHP에서 :에
/****
* Schedule a command using the AT command
*
* To do this you need to ensure that the www-data user is allowed to
* use the 'at' command - check this in /etc/at.deny
*
*
* EXAMPLE USAGE ::
*
* scriptat('/usr/bin/command-to-execute', 'time-to-run');
* The time-to-run shoud be in this format: strftime("%Y%m%d%H%M", $unixtime)
*
**/
function scriptat($cmd = null, $time = null) {
// Both parameters are required
if (!$cmd) {
error_log("******* ScriptAt: cmd not specified");
return false;
}
if (!$time) {
error_log("******* ScriptAt: time not specified");
return false;
}
// We need to locate php (executable)
if (!file_exists("/usr/bin/php")) {
error_log("~ ScriptAt: Could not locate /usr/bin/php");
return false;
}
$fullcmd = "/usr/bin/php -f $cmd";
$r = popen("/usr/bin/at $time", "w");
if (!$r) {
error_log("~ ScriptAt: unable to open pipe for AT command");
return false;
}
fwrite($r, $fullcmd);
pclose($r);
error_log("~ ScriptAt: cmd=${cmd} time=${time}");
return true;
}
봐 ['at'] (http://unixhelp.ed.ac.uk/CGI/man-cgi?at) – arnaud576875
아르노의 그것을 얻었다. 'at '는 특정한 시간에 일자리를 구하는 일이다. cron은 반복되는 작업입니다. at와 cron은 모두 스케줄링에 1 분 단위로 세분화되어 있으므로 두 번째가 필요하면 직접 지연해야합니다. –
그들이 빈번하다면, 매시간 크론 작업이 가장 좋은 아이디어라고 생각합니다. 중복되는 문제가 무엇인지 확실하지 않은 경우 문제없이 동시에 여러 번 호출되는 동일한 스크립트를 사용할 수 있습니다. 외모가 좋을 때 –