ã¯ããã«
ãcronã¯chronographï¼ã¯ããã°ã©ãï¼ã®ç¥ã§ãæå®ããæ¥ä»ãæå»ã«ãã¾ãã¯ä¸å®ã®ééã§ãã¹ã¯ãªããã®å®è¡ãããã°ã©ã ã®éå§ããã¥ã¼ã¹ã¬ã¿ã¼ã®éä¿¡ããã¼ã¿ãã¼ã¹ã®ããã¯ã¢ãããã¡ãã»ã¼ã¸ã®è¡¨ç¤ºãä¸è¦ãªãã¡ã¤ã«ã®åé¤ãªã©ãè¡ãããã«ä½¿ãããããã»ã¹ã§ããä¸è¬ã«ãã³ã³ãã¥ã¼ã¿ã§èªåçã«å®è¡ãããããã»ã¹ã¯ãã¹ã¦cronã§ããæ¬ç¨¿ã§ã¯ãPHPã¹ã¯ãªãããcronã¨ãã¦å®è¡ããæ¹æ³ã説æãã¾ãã
PHPã®cronã¨Linux
ãLinuxã«ã¯ãç¹å®ã®å¨æã§å®è¡ãããããã»ã¹ã管çããããã®ä¾¿å©ãªæ段ã¨ãã¦ãcronãã¼ã¢ã³ï¼crondï¼ãç¨æããã¦ãã¾ããã¦ã¼ã¶ã¼ã¯ãå®è¡ããã¹ã¯ãªãããã³ãã³ãããcrontabããã¡ã¤ã«ã§å®ç¾©ãã¾ããcrontabãã¡ã¤ã«ã«ã¯ãæç³»åã§å®è¡ãããä¸é£ã®ã¿ã¹ã¯ãè¨è¿°ããã1è¡ã1ã¤ã®ã¨ã³ããªã表ãã¾ããåã¨ã³ããªã«ã¯ãã¿ã¹ã¯ã®å®è¡æ¹æ³ï¼ã¹ã¯ãªãããå®è¡ãããªã©ï¼ã«é¢ããæ å ±ãæå®ããã¾ãããããã®åã ã®ã¿ã¹ã¯ããcronã¸ã§ããã¨å¼ã³ã¾ãã
ãcrontabãã¡ã¤ã«ã¯ã¦ã¼ã¶ã¼ãã¨ã«ä½æãããã®ã§ãåã¦ã¼ã¶ã¼ãç¬èªã®cronãå®è¡ã§ãã¾ãã
ãcrontabãã¡ã¤ã«ãæä½ããã«ã¯ã次ã®æ§æã使ãã¾ãã
# crontab [--e [-u username] | -l [-u username] | -r [-u username] | file]
ãå¼æ°-e
ã¯ãããã©ã«ãã®ã¨ãã£ã¿ï¼viãªã©ï¼ã使ã£ã¦ãã¡ã¤ã«ãç·¨éãããã¨ãæå³ãã¾ããç·¨éãçµããã¨ããã¡ã¤ã«ã¯ç¾å¨ã®ã¦ã¼ã¶ã¼ã®crontabãã¡ã¤ã«ã¨ãã¦ãcronããã£ã¬ã¯ããªã«ã¤ã³ã¹ãã¼ã«ããã¾ããcrontabãã¡ã¤ã«ãæ¢ã«åå¨ããå ´åã¯ä¸æ¸ãããã¾ããå¼æ°-l
ã¯ããã¡ã¤ã«ã®å
容ã表示ãã¾ããå¼æ°-r
ã¯ããcrontabããã£ã¬ã¯ããªãããã¡ã¤ã«ãåé¤ãã¾ãã
ãå¼æ°-u
ï¼usernameï¼ã®å¾ãã®usernameã¯çç¥å¯è½ã§ãããã©ã®ã¦ã¼ã¶ã¼ã®crontabãã¡ã¤ã«ãæä½ããããæå®ãã¾ããä¾ãã°ãrootã¦ã¼ã¶ã¼ã¯usernameã使ã£ã¦ãç¹å®ã®crontabãã¡ã¤ã«ã®ææè
ãæå®ã§ãã¾ããusernameå¼æ°ãæå®ããªãå ´åã¯ãç¾å¨ã®ã¦ã¼ã¶ã¼ã®crontabãã¡ã¤ã«ãæä½å¯¾è±¡ã«ãªãã¾ããç¡å¹ãªusernameå¼æ°ãæå®ããå ´åã¯ãã³ãã³ããå®è¡ããã¨ã¨ã©ã¼ãçºçãã¾ãã
ãfileå¼æ°ã¯ãæå®ãããã¡ã¤ã«ã®å 容ã§crontabãã¡ã¤ã«ãç½®ãæãã¾ããç½®ãæãããã¡ã¤ã«ã®å 容ãcronãã¼ã¢ã³ã®æ¸å¼ã¨ä¸è´ãã¦ããªãã¨ãcrontabã³ãã³ããæ£ããåä½ãã¾ããã
crontabãã¡ã¤ã«ã®æ§æ
ããã®ãã¡ã¤ã«ã®æ§æã¯ã¨ã¦ãéè¦ã§ããæ§æã®è¨è¿°ã誤ãã¨ãcrontabã¯æ£ããæ©è½ãã¾ããããã¡ã¤ã«ã®åè¡ã«ã¯ã表1ã«ç¤ºã6ã¤ã®ãã£ã¼ã«ãã1ã¤ãã¤é çªã«è¨è¿°ããå¿ è¦ãããã¾ããåè¡ã®åºåãã«ã¯æ¹è¡æåã使ãã¾ãã
ãã£ã¼ã«ã | 説æ |
---|---|
å | 0ï½59ã®æ°å¤ |
æ | 0ï½23ã®æ°å¤ |
æ¥ | 1ï½31ã®æ°å¤ |
æ | 1ï½12ã®æ°å¤ |
ææ¥ | 0ï½6ã®æ°å¤ï¼0ã¯æ¥ææ¥ã6ã¯åææ¥ï¼ |
ã³ãã³ã | å®è¡ããã¹ã¯ãªããåã¾ãã¯ã³ãã³ã |
ãæåã®5ã¤ã®ãã£ã¼ã«ãã®å 容ã¯ã次ã®ããã«ããã¤ãã®æ¹æ³ã§è¨å®ã§ãã¾ãã
- 1ã¤ã®æ°å¤ã§è¨å®ãã
ä¾ãã°ããåããã£ã¼ã«ãã6
ã«è¨å®ããã¨ãã¹ã¯ãªããã¯æ¯æ6åã«å®è¡ããã¾ãã - ç¯å²ã§è¨å®ãã
ä¾ãã°ããæããã£ã¼ã«ãã2+9
ã«è¨å®ããã¨ãã¹ã¯ãªããã¯åå2:00ããåå9:00ã¾ã§æ¯æéå®è¡ããã¾ãã - ã³ã³ãåºåãã®å¤ã®ãªã¹ãã§è¨å®ãã
ä¾ãã°ããæããã£ã¼ã«ãã2,5,9
ã«è¨å®ããã¨ãã¹ã¯ãªããã¯åå2:00ãåå5:00ãããã³åå9:00ã«å®è¡ããã¾ãã - ã¢ã¹ã¿ãªã¹ã¯ï¼
*
ï¼ã§è¨å®ãã
ã¢ã¹ã¿ãªã¹ã¯ã¯ããã®ãã£ã¼ã«ãã®ãã¹ã¦ã®å¤ã«ä¸è´ããã¯ã¤ã«ãã«ã¼ãã§ãã - ã¢ã¹ã¿ãªã¹ã¯ã¨å¤ã§è¨å®ãã
ä¾ãã°ããåããã£ã¼ã«ãã*/5
ã«è¨å®ããã¨ãã¹ã¯ãªããã¯5åããã«å®è¡ããã¾ãã
ã6çªç®ã®ãã³ãã³ãããã£ã¼ã«ãã«ã¯ãå®è¡ããã¹ã¯ãªããåã¾ãã¯ã³ãã³ããæå®ãã¾ãã
ããããå¿ é ã®ãã£ã¼ã«ãã®ã»ãã«ãå¿ è¦ã«å¿ãã¦æ¬¡ã®ãªãã·ã§ã³ã®å¼æ°ã使ã£ã¦ããã°ãã¡ã¤ã«ãã¨ã©ã¼ãã¡ã¤ã«ãçæãããã¨ãã§ãã¾ãã
- ãã°ãã¡ã¤ã«
äºéã®å³åãå±±ãã£ãï¼>>
ï¼ã¨ãã°ãã¡ã¤ã«åã使ã£ã¦ãã°ãã¡ã¤ã«ãæå®ãã¾ãï¼ä¾ï¼>>cron.log
ï¼ã - ã¨ã©ã¼ãã¡ã¤ã«
ãã¬ãã£ãã¯ã¹ï¼2>>
ï¼ã¨ã¨ã©ã¼ãã¡ã¤ã«åã使ã£ã¦ã¨ã©ã¼ãã¡ã¤ã«ãæå®ãã¾ãï¼ä¾ï¼2>>cron.err
ï¼ã