Iiwebhusayithi zinokuqhuba imisebenzi ecwangcisiweyo kunye neCron

iwashi

Sineenkqubo ezininzi zokubeka iliso emsebenzini eziqhuba iinkqubo rhoqo. Abanye babaleka umzuzu ngamnye, abanye kanye ngobusuku kuxhomekeke kwinto abayenzayo. Umzekelo, sinokuqhuba iskripthi esithumela ngaphandle bonke abathengi abangakhange bathenge kwiintsuku ezingama-30 ukubathumela isigqebhezana.

Endaweni yokuzama ukugcina umkhondo wazo zonke ezi zinto ngesandla, kulula kakhulu ukwakha imisebenzi ecwangciswe ngokuzenzekelayo kwaye yenziwe. Kwiinkqubo ezisekwe kwi-Unix, oku kuyenziwa ngeCron. Kuni bantu niyaziyo into eniyenzayo, zive ukhululekile ukundifundisa kunye nabafundi ukuba ndilahla nayiphi na into engachazwanga.

Ngelishwa, kodwa umphuhlisi oqhelekileyo wewebhu akaqhelananga neCron kwaphela. Nokuba zikhona, iinkampani zokubamba iwebhu zihlala zinganikezeli ukufikelela, okanye inkxaso yeCron. Umbuki zindwendwe wam ungomnye wokugqibela - bayakuvumela ukuba uyisebenzise, ​​kodwa abaxhasi.

Yintoni iCron?

Ikron ibizwa ngegama lesiGrike uChronos, elithetha intsingiselo ixesha. ICron ibaleka kwilogu eqhubekayo yokuqhuba imisebenzi eqokelelwe yiCrontab (mhlawumbi ebizwa ngokuba yi- tabisilonda. Loo misebenzi ibizwa ngokuba ziiCronjobs, kwaye inokubhekisa kwizikripthi kwindawo yakho.

Ingcaciso yeCron Diagram

Ndiyiseta njani iCrontab

Ukufumana i-Cron yokubaleka kunokuba ngumceli mngeni, ke nantsi into endiyifundileyo kwaye ndiyenzele njani Ukuba Uyaphumelela:

  1. Ndicwangcise iskripthi sam ukujonga i-Twitter's API ukubona ukuba akukho mntu uphendulileyo na @syabonga. Ndithelekise loo miyalezo kunye nemiyalezo esele ndiyigcinile kwiwebhusayithi, ndingena kuyo nayiphi na emitsha.
  2. Nje ukuba iskripthi sisebenze, ndenza ukuba imvume yoMsebenzisi iphumeze iskripthi (744) kwaye ndongeze ireferensi yeskripthi kwifayile yam yeCronjob-ngakumbi emva koko.
  3. Kuya kufuneka ndingene kwiwebhusayithi yam ngeSSH. Kwi-Mac, ethathe ukuvula iTheminali kunye nokuchwetheza Igama lomsebenzisi leSSH@domain.com apho igama lomsebenzisi ligama lomsebenzisi endinqwenela ukulisebenzisa kunye ne-domain yayiyiwebhusayithi. Ndaye ndacelwa ukuba ndinike igama eligqithisiweyo.
  4. Ndizamile ke ukusebenzisa iskripthi ngqo kwi-Prompt yomyalelo ngokuchwetheza igama lefayile kunye nendlela ehambelana kwiseva: /var/www/html/myscript.php
  5. Nje ukuba ndiyisebenze ngokuchanekileyo, ndongeze ikhowudi ye-Unix eyimfuneko kumgca wokuqala wefayile: #! / usr / bin / php -q . Ndiyakholelwa ukuba oku ngokulula kuxelela i-Unix ukuba isebenzise i-PHP ukwenza iskripthi.
  6. Kumgca wokuyalela wesiphelo sendlela, ndichwethezile crontab (abanye banokufuna ukuchwetheza i-crontab -e) Kwaye hit hit… kwaye yayikukuphela kwento eyayifuneka!

Isintax kwifayile yakho yeCronjob

Ngokumalunga ne- # 2 apha ngasentla, iCron isebenzisa iskimu sobuchule sokumisela ukuba ziya kwenziwa nini izikripthi zakho. Ngapha koko, unokukopa kwaye uncamathisele kwifayile yakho yeCron (kumamkeli wam, ibekwe kuyo / var / spool / ikron / ngegama lefayile elifanayo negama lomsebenzisi).

# + ——————- umzuzu (0 - 59)
# | + ————- iyure (0 - 23)
# | | + ———- usuku lwenyanga (1 - 31)
# | | | + ——- inyanga (1 - 12)
# | | | | + - - usuku lweveki (0 - 6) (ngeCawa = 0 okanye 7)
# | | | | |
* * * * * /var/www/html/myscript.php

Oku kungasentla kuya kwenza iskripthi sam yonke imizuzu. Ukuba bendifuna ibaleke kube kanye ngeyure, bendizakubeka nje imizuzu emingaphi emva kweyure endinqwenela ukuba iqhubeke, ukuba ibikwimizuzu engama-30:

30 * * * * /var/www/html/myscript.php

Qiniseka ukuba useta iimvume kule fayile njengezinokuphunyezwa, nazo! Ndifumanise ukuba is syntax, iimvume, kunye nokwenza i-crontab kwiwindows yeTheminali zezona zinto zibalulekileyo. Qho xa ndigcina ifayile, ndiza kufumana iimvume zam ezifuna ukuseta kwakhona!

(~ # ~) Hlaziya (~ # ~): Ukuba ungathanda ukuqinisekisa ukuba imisebenzi iyasebenza, enye indlela elula kukuhlaziya indawo yedatha ngexesha lokugqibela ukubhalwa kweskripthi. Ukuba yinto engafane yenzeke, unokubhala nje i-imeyile ethunyelwe kuwe.

Izixhobo ezongezelelweyo zeCron:

Zingaphi imisebenzi onokuzenzekelayo usebenzisa iCron?

8 Comments

  1. 1

    Inqaku eligutyungelwe kakuhle lokumisela ikhron, yomntu omtsha kwii-crojobs, elona candelo linzima ekusetyenzisweni kwekron kukufumanisa ixesha lokuphunyezwa kwe-cronjob, kwaye kuyinto entle ukufumana ixesha elingalunganga ekuqaleni. Ukuba ii-cronjobs zakho zinobuzaza ngexesha, kulungile ukuba ubandakanye ezinye iikhowudi kwiskripthi sokubonisa imeko ukuze ugcine unolwazi ngemeko yokuphunyezwa komsebenzi.

  2. 2

    Molo Doug,

    Izinto ezimbalwa ekufuneka ziqwalaselwe xa usebenza nemisebenzi yekron.

    Kuqala, emva kweshumi elinambalwa, uya nqwenela ukuba une-UI, indawo yogcino lwedatha kunye nes syntax ejonge isiNgesi

    Okwesibini, i-cron iya kuwutshisa umsebenzi ngexesha elichaziweyo, nokuba ukubanjwa kwangaphambili komsebenzi kugqityiwe na. Ukuqhuba umsebenzi kube kanye ngomzuzu othatha imizuzu emi-2 kuya kukhokelela ngokukhawuleza kwimisebenzi efanayo yokusebenza.

    Okulandelayo, akukho ecaleni kwengxelo yempazamo xa kukho into ehamba gwenxa, ke kuyakufuneka ukongeze eyakho impazamo yokuxela.

    Ndizidibanise neendlela ngeendlela:
    -Isicelo esiveliswe ngokujonga ikron kwindawo yogcino lwedatha ukumisela ukuba yeyiphi ekufuneka yenziwe. Yigijime kanye ngomzuzu okanye ngeyure kuxhomekeke kwinto oyifunayo
    Isikripthi ngasinye masenze ifayile 'yokutshixa' kwi / tmp kwaye ukuba sikhona, ungaqali kwakhona, oku kuthintela imisebenzi ephindwayo ukuba awuyifuni
    -Ukuba iskripthi sifumana ifayile yokutshixa indala kuneyure enye (okanye nantoni na ebonisa ukuba ubhubhile) thumela isilumkiso se-imeyile
    -Skripthi sithumele i-imeyile malunga nokusilela komsebenzi ukuze wazi ukuba kukho into engahambanga kakuhle
    -Jonga kwizakhelo ezinje ngeFlux okanye ishedyuli yorhwebo xa iimfuno zakho zingaphaya kwezikripthi ezimbalwa

    Chris

  3. 4

    Ndiza kongeza ukuba kwiinkqubo ezininzi zeLinux / Unix, "crontab -e" Yile nto uyisebenzisayo ukuhlela i-crontab yakho. Ndicinga ukuba umphathi wakho (iJumpline) usebenzisa ingxelo eguqulweyo ngenxa yezizathu zokhuseleko.

  4. 5

    Ndisalukhumbula usuku lokuqala endadibana nalo uCronnie. Ndakhe ndeva izinto ngaye, ukuba wayenokuthenjwa, uhlala ngexesha, kodwa ngamanye amaxesha edideka malunga neenjongo zakhe.

    Ndifumene le iyinyani njengoko wayeyimfihlakalo epheleleyo kum ekuqaleni. Emva kokubuza ngeenxa zonke ngaye, ndaye ndayibamba ngokukhawuleza indlela awayekuthanda ngayo ukusebenza. Ngoku, andinakucinga ukuba usuku ludlula ngaphandle kwakhe ebomini bam. Wenza ubumnandi obuqhelekileyo, kwaye ususa umthwalo emininzi emagxeni am.

    Kubo bonke ubunzulu, ndiziva ngathi ndikrwece kuphela umphezulu ngento endinokuzenzekelayo nayo ngemisebenzi yekron. Ngokwenene ngabaphuhlisi abangabona bahlobo. Ukuba usebenzisa umntu onjengeCPanel ukulawula iserver yakho, ibonelela ngonxibelelwano olunobuhlobo ngakumbi ukwenza iicron. Gcwalisa ngeemenyu zokuhla ezantsi zomzuzu, iyure, usuku, inyanga, njl njl.

  5. 7

    Ngokuqinisekileyo ndiyabona ukuba le yinto ekufuneka yenziwe ngabathengisi bonke… Ingaba ukhona umntu onokubonelela ngale nkonzo kuba ivakala ngathi “bubuchwephesha”?

Ingaba ucinga ntoni?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda indlela idatha yakho yokubhaliweyo isetyenziswe ngayo.