Amawebhusayithi Angasebenza Imisebenzi Ehleliwe ngeCron

Iwashi

Sinezinhlelo eziningi zokuqapha ezingasasebenzi emsebenzini ezenza izinqubo njalo. Abanye bagijima njalo ngeminithi, abanye kanye ngobusuku kuya ngokuthi benzani. Isibonelo, singaqalisa iskripthi esikhiphela wonke amakhasimende angathenganga ezinsukwini ezingama-30 ukuwathumela isigqebhezana.

Esikhundleni sokuzama ukulandela umkhondo wazo zonke lezi zinto ngesandla, kulula kakhulu ukwakha imisebenzi ehlelwa ngokuzenzekelayo futhi yenziwe. Kuzinhlelo ezise-Unix, lokhu kufezwa ngeCron. Kini bantu abakwaziyo okwenzayo, zizwe ukhululekile ukungifundisa mina nabafundi uma ngilahla noma yiluphi ulwazi olungelona iqiniso.

Kuyishwa, kepha umakhi wewebhu ojwayelekile akayazi iCron nhlobo. Noma ngabe zikhona, izinkampani zokubamba iwebhu kaningi azihlinzeki ngokufinyelela, noma ukuxhaswa kweCron. Umbungazi wami ungomunye walaba bakamuva - bayakuvumela ukuthi uyisebenzise, ​​kepha abayisekeli.

Yini iCron?

I-Cron ibizwa ngegama lesiGreki elithi Chronos, elisho isikhathi. I-Cron isebenza ku-loop eqhubekayo ukwenza imisebenzi eqoqwe yiCrontab (mhlawumbe ebizwa ngegama le- ithebhuisilonda. Leyo misebenzi ibizwa ngokuthi yiCronjobs, futhi ingabheka imibhalo kusayithi lakho.

Incazelo Yomdwebo weCron

Ngiyisetha kanjani iCrontab

Ukwenza iCron isebenze empeleni kungaba yinselele, ngakho-ke nakhu engikufundile nokuthi ngikwenzele kanjani Uma Suck:

  1. Ngisetha iskripthi sami ukuze ngihlole ama-Twitter API ukubona ukuthi ukhona yini ophendulile @sbahle_mpisane. Ngiqhathanise leyo milayezo nemiyalezo esengivele ngiyigcine kuwebhusayithi, ngifaka noma iyiphi emisha.
  2. Lapho iskripthi sisebenza, nganika amandla imvume yoMsebenzisi ukwenza iskripthi (744) futhi ngangeza ireferensi yeskripthi kufayela lami leCronjob - ngaphezulu kwalokho kamuva.
  3. Ngibe sengingena ngemvume kuwebhusayithi yami ngeSSH. Ku-Mac, lokho kuthathe ukuvula iTheminali nokuthayipha Igama lomsebenzisi le-SSH@domain.com lapho igama lomsebenzisi kwakuyigama lomsebenzisi engangifisa ukulisebenzisa nesizinda kwakuyiwebhusayithi. Ngabe sengikhutshelwa futhi nganika iphasiwedi.
  4. Ngibe sengizama ukusebenzisa iskripthi ngqo kusuka ku-Prompt yomyalo ngokuthayipha igama lefayela nendlela ehlobene kuseva: /var/www/html/myscript.php
  5. Lapho sengikusebenze kahle, ngangeza ikhodi edingekayo ye-Unix kulayini wokuqala wefayela: #! / usr / bin / php -q . Ngikholwa ukuthi lokhu kumane kutshele i-Unix ukuthi isebenzise i-PHP ukwenza iskripthi.
  6. Emgqeni womyalo weTheminali, ngathayipha i-crontab (abanye bangadinga ukuthayipha i-crontab-e) bese ushaya u-enter… futhi yilokho kuphela obekudingeka!

I-syntax yefayela lakho le-Cronjob

Mayelana ne- # 2 ngenhla, iCron isebenzisa isikimu esihlakaniphile sokunquma ukuthi imibhalo yakho izokwenziwa nini. Eqinisweni, ungakopisha futhi unamathisele lokhu ku-Cronfile yakho (ku-Host yami, itholakala ku- / var / spool / cron / ngegama lefayela elifanayo negama lami lomsebenzisi).

# + —————- iminithi (0 - 59)
# | + ————- ihora (0 - 23)
# | | + ——— - usuku lwenyanga (1 - 31)
# | | | + ——-- inyanga (1 - 12)
# | | | | + —- usuku lwesonto (0 - 6) (NgeSonto = 0 noma 7)
# | | | | |
* * * * * /var/www/html/myscript.php

Lokhu okungenhla kuzosebenzisa iskripthi sami njalo ngeminithi. Ukube bengifuna ukuthi isebenze kanye ngehora, bengizobeka nje ukuthi mangaki imizuzu ngemuva kwehora engifisa ukuthi isebenze, ngakho-ke uma bekumaki wemizuzu engama-30:

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

Qiniseka ukuthi usetha izimvume kuleli fayela njengezisebenzisekayo, futhi! Ngithole ukuthi i-syntax, izimvume, nokwenza i-crontab kusuka ewindini leTheminali yizinto ezibaluleke kakhulu. Njalo lapho ngigcina ifayela, bengizithola izimvume zami zidinga ukusethwa kabusha!

QAPHELA: Uma ungathanda ukuqinisekisa ukuthi imisebenzi iyasebenza, enye indlela elula ukuvuselela inkambu yedatha nesikhathi sokugcina lapho iskripthi sisebenza khona. Uma kungavamile kakhulu, ungavele ubhalele i-imeyili ethunyelwe kuwe.

Izinsizakusebenza zeCron ezingeziwe:

Mingaki imisebenzi ongayisebenzisa usebenzisa iCron?

8 Amazwana

  1. 1

    I-athikili embozwe kahle ngokusetha i-cron, kumuntu omusha kuma-crojobs, ingxenye enzima kunazo zonke ekumiseni i-cron ukuthola isikhathi sokubulawa kwe-cronjob, futhi kuyafana impela ukuthola isikhathi esingalungile ekuqaleni kokuzama. Uma ama-cronjobs akho ezwela ngesikhathi, kuhle ukufaka amakhodi athile kuskripthi ukuzwakalisa isimo ukuze ugcine waziswa ngesimo sokwenza umsebenzi.

  2. 2

    Sawubona Doug,

    Izinto ezimbalwa okufanele uzicabangele lapho usebenza ngemisebenzi ye-cron.

    Okokuqala, ngemuva kweshumi nambili, uzofisa ukuthi ube ne-UI, i-database kanye ne-syntax ebukeka ngesiNgisi

    Okwesibili, i-cron izowushisa umsebenzi ngesikhathi esibekiwe, noma ngabe ukucelwa kwangaphambilini komsebenzi kuqediwe. Ngakho-ke ukuqhuba umsebenzi kanye ngomzuzu othatha imizuzu emi-2 kuzoholela masinyane ekusebenzeni okufanayo.

    Okulandelayo, akukho okubikwa kwephutha lapho kukhona okungahambi kahle, ngakho-ke kuzodingeka ungeze okwakho ukubika kwephutha.

    Ngibhekise lokhu ngezindlela ezimbalwa:
    - uhlelo lokusebenza luqaliswe ngokubheka i-cron ku-database ukuthola ukuthi yini edinga ukwenziwa. Qalisa kanye ngomzuzu noma ngehora kuye ngokuthi ufunani
    - ukuthi umbhalo ngamunye udale ifayili 'lokukhiya' ku / tmp futhi uma likhona, ungaqali futhi, lokhu kuvimbela imisebenzi eyimpinda uma ungafuni
    - uma iskripthi sithola ifayela lokukhiya lidala kunehora eli-1 (noma noma yini esikisela ukuthi ushonile) thumela isexwayiso se-imeyili
    - iskripthi sithumele i-imeyili ngokuhluleka komsebenzi ukuze wazi ukuthi kukhona okungahambanga kahle
    - bheka izinhlaka ezinjengeFlux noma abahleli bezentengiso lapho izidingo zakho zidlula imibhalo embalwa

    Chris

  3. 4

    Ngizongeza nokuthi kuzinhlelo eziningi zeLinux / Unix, “crontab -e” Yilokho okusebenzisa ukuhlela i-crontab yakho. Ngicabanga ukuthi umphathi wakho (i-Jumpline) usebenzisa inguqulo eguquliwe ngezizathu zokuphepha.

  4. 5

    Ngisalukhumbula usuku lokuqala engahlangana ngalo noCronnie. Ngangizwile izinto ngaye, ukuthi wayethembekile, ngaso sonke isikhathi ngesikhathi, kepha kwesinye isikhathi edideka ngezinhloso zakhe.

    Ngithole ukuthi lokhu kuyiqiniso njengoba ekuqaleni ubeyimfihlakalo kimi. Ngemuva kokubuza ngakubo, ngabamba ngokushesha ukuthi uthanda kanjani ukusebenza. Manje, angikwazi ukucabanga ukuthi usuku luzodlula ngaphandle kwakhe empilweni yami. Wenza okungajwayelekile kumnandi, futhi ususa imithwalo eminingi emahlombe ami.

    Kukho konke ukungathí sina, ngizizwa sengathi ngiklwebhe ingaphezulu kuphela ngalokho engingakwenza ngemishini yekrononi. Bangabangane abakhulu bonjiniyela bangempela. Uma usebenzisa umuntu ofana neCPanel ukuphatha iseva yakho, inikeza isikhombimsebenzisi esibonakalayo esinobungane ngokwengeziwe ukudala ama-crons. Qedela ngamamenyu okwehla okomzuzu, ihora, usuku, inyanga, njll. Okwakhela umugqa we-cron.

  5. 7

    Ngibona nakanjani lokhu kuyinto okumele yenziwe yibo bonke abamakethi… Ngabe ukhona yini umuntu onganikeza le sevisi ngoba kuzwakala “kuyitheknoloji” kakhulu?

UCABANGANI?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda ukuthi idatha yakho yokuphawula isetshenziswa kanjani.