Cov Lus Zais Kom Ceev Hauv WordPress Lub Vas Sab: Tshem Tawm Cov Haujlwm CRON Uas Teem Tseg Tsis Tau

Qhov phem tshaj plaws rau lub web server tsis yog lub sijhawm tsis ua haujlwm, tab sis raug rub los ntawm cov haujlwm tsis muaj txiaj ntsig.

WordPress Hauv ntiaj teb ntawm WP-Cron, nws zoo li lub moos tsis pom, ntsiag to teem sijhawm ntau yam haujlwm raws sijhawm.

Chiv thawj nws yog ib qho cuab yeej pab tau, tab sis nws feem ntau dhau los ua tus neeg tua neeg tsis pom uas ua rau qeeb qeeb vim yog "zombie tasks" uas tshuav tom qab uninstalling plugins.

Qhov xwm txheej thiab kev phom sij zais ntawm WP-Cron

WP-Cron tsis yog Cron theem system, tab sis yog ib txoj haujlwm teem sijhawm uas WordPress nws tus kheej simulated.

Nws tsuas yog xyuas seb puas muaj cov haujlwm twg yuav tsum tau ua thaum tus neeg siv nkag mus rau.

Qhov no txhais tau tias yog tias ib qho plugin sau npe ua haujlwm txhua hnub, txoj haujlwm ntawd tseem yuav muaj txawm tias lub plugin raug tshem tawm.

Qhov tshwm sim yog tias WordPress tab tom sim ua kom tiav qhov hook uas tsis muaj nyob txhua hnub.

Qhov no tsis yog tsuas yog nkim cov peev txheej xwb, tab sis kuj tseem yuav ua rau muaj cov ntaub ntawv tsis raug hauv lub database.

Raws li cov ntaub ntawv raug cai ntawm WordPress tus tsim tawm, WP-Cron txoj haujlwm teem sijhawm nyob ntawm ... _get_cron_array() Txhawm rau kom tau txais txhua yam haujlwm uas tau sau npe.

Yog tias qhov kev ua haujlwm sib xws rau tus nuv tsis muaj lawm, lub kaw lus tseem yuav sim ua nws, tab sis thaum kawg nws tsuas yog tig mus tsis muaj lub hom phiaj.

Vim li cas ho ntxuav cov haujlwm tsis tau teem sijhawm?

Xav txog koj lub vev xaib WordPress ua ib lub chaw ua haujlwm.

Cov neeg ua haujlwm ua haujlwm raws sijhawm txhua hnub, tab sis qee tus ntawm lawv twb tawm hauv lub tuam txhab lawm.

Lawv cov lej ID neeg ua haujlwm tseem nyob hauv lub kaw lus, thiab lub tshuab tuaj koom tos lawv kom lawv rho lawv daim npav txhua hnub.

Qhov no yog kev ua haujlwm CRON tsis raug.

Yog tias tsis ntxuav ntev, lub hauv paus ntaub ntawv yuav muaj... wp_options Lub rooj yuav puv thiab tsis siv tau. _transient cov ntaub ntawv.

Qhov phem dua, kev kuaj xyuas tsis raug ntau zaus ua rau muaj kev ua haujlwm ntau ntxiv ntawm PHP.

Kev tshawb fawb qhia tau tias ntau tshaj [tus lej] WordPress cov vev xaib 30% kev pov tseg ntawm kev ua haujlwmQhov no yog vim muaj cov haujlwm CRON tsis raug lossis rov ua dua (Qhov chaw: Smashing Magazine Technical Analysis).

Kev siv cov lej rau kev tshem tawm cov haujlwm tsis raug

Cov kev daws teeb meem no yeej zoo nkauj heev.

Cov Lus Zais Kom Ceev Hauv WordPress Lub Vas Sab: Tshem Tawm Cov Haujlwm CRON Uas Teem Tseg Tsis Tau

Peb tsuas yog yuav tsum khiav ib daim ntawv sau nrhiav txhua hnub kom luam theej txhua yam haujlwm uas tau teem sijhawm tseg, thiab yog tias nws pom tias qhov kev ua haujlwm sib raug rau qhov hook tsis muaj lawm, nws yuav tshem nws tawm.

Cov lej ua haujlwm hauv qab no tuaj yeem ua tiav qhov no:

add_action('wpcwl_remove_invild_crons', function(){
    global $wp_filter;

    $wp_crons = _get_cron_array();

    foreach ($wp_crons as $timestamp => $wp_cron) {
        foreach ($wp_cron as $hook => $dings) {
            if(empty($wp_filter[$hook])){
                foreach( $dings as $sig=>$data ) {
                    wp_unschedule_event($timestamp, $hook, $data['args']);
                }
            }
        }
    }
});

if(!wp_next_scheduled('wpcwl_remove_invild_crons')) {
    wp_schedule_event( time(), 'daily', 'wpcwl_remove_invild_crons' );
}

Cov cai no ua peb yam:

  1. Rov ua dua txhua yam haujlwm uas tau teem tseg:pass _get_cron_array() Rov qab tau cov haujlwm uas tau sau npe tam sim no.
  2. Sim seb tus nuv puas ua haujlwm tau zoo:yog tias $wp_filter[$hook] Yog tias nws khoob, nws txhais tau tias tsis muaj lub luag haujlwm sib xws rau qhov nuv no.
  3. Tshem tawm cov haujlwm tsis raug: hu xov tooj wp_unschedule_event() Rho tawm txoj haujlwm.

Thaum kawg, nws kuj tau sau npe ua haujlwm txhua hnub kom ntseeg tau tias muaj kev tu txhua hnub.

Kev tshuaj xyuas tob ntawm cov lej logic

Muaj ntau tus neeg pom cov lej no nyuaj, tab sis qhov logic yeej yooj yim heev:

  • Lub voj voog thawj zaug: Rov ua dua txhua txoj haujlwm los ntawm lub sijhawm.
  • Lub voj thib obTshawb xyuas cov haujlwm los ntawm lub npe hook.
  • Lub voj thib pebNtxuav cov haujlwm los ntawm cov kos npe ua haujlwm thiab cov kev teeb tsa ib qho los ntawm ib qho.

Txoj kev ua zes peb theem no ua kom ntseeg tau tias tsis muaj txoj haujlwm tsis raug uas ploj lawm.

thiab wp_unschedule_event() Qhov no yog txoj kev tshem tawm uas WordPress pom zoo, thiab nws tseem yuav ntxuav cov ntaub ntawv cuam tshuam hauv lub database.

Cov xwm txheej ntawm daim ntawv thov hauv ntiaj teb tiag

Piv txwv li.

Koj tau teeb tsa ib qho SEO Lub plugin tsim ib daim ntawv qhia chaw txhua hnub.

Koj tom qab ntawd tau uninstall lub plugin, tab sis nws txoj haujlwm CRON tseem nyob.

Qhov tshwm sim yog tias WordPress sim ua txhua hnub. seo_generate_sitemap Tus nuv no.

Vim tias qhov function no tsis muaj lawm, lub system tsuas yog ua haujlwm tsis muaj txiaj ntsig xwb.

Yog koj qhib qhov code saum toj no, txoj haujlwm tsis raug no yuav raug ntxuav tawm hnub tom qab.

Kev txhim kho kev ua tau zoo

Raws li cov ntaub ntawv sim tiag tiag, lub vev xaib WordPress nruab nrab (kwv yees li 50 plugins) tom qab qhib kev ntxuav tsis siv neeg:

  • Cov lus nug hauv database txo qis 12%.
  • Qhov ceev ntawm nplooj ntawv thauj khoom tau zoo dua 0.3 vib nas this.
  • Cov haujlwm tsis siv tau txhua hnub raug txo qis 20+ xyoo.

Cov ntaub ntawv no los ntawm kev sim sib piv hauv daim ntawv qhia kev ua tau zoo ntawm WP Engine.

Cov kev coj ua zoo tshaj plaws thiab cov lus qhia txog kev ua kom zoo dua

Ntxiv rau kev ntxuav tsis siv neeg, ntawm no yog ob peb lub tswv yim txhim kho:

  • Tshawb xyuas cov haujlwm CRON tsis tu ncuaSiv cov plugins xws li WP Crontrol, koj tuaj yeem pom txhua yam haujlwm.
  • Txo cov plugins uas tsis tseem ceebThaum koj uninstall ib lub plugin, nws yog qhov zoo tshaj plaws los manually clear nws cov scheduled tasks.
  • Siv Cron theem systemRau cov vev xaib uas muaj neeg coob coob, nws raug pom zoo kom lov tes taw WP-Cron thiab siv lub server Cron tiag tiag hloov chaw.

Qhov no zam WP-Cron cov teeb meem kev nkag mus rau qhov chaw nyob thiab ruaj khov dua.

Xaus Lus: Khaws WordPress kom huv si

Cov haujlwm WordPress teem sijhawm zoo li ib pab pawg.

Txhua lub plugin zoo li ib tug neeg ua suab paj nruag, txhua tus ua nws lub luag haujlwm los tsim ib zaj nkauj sib haum xeeb.

Tab sis yog tias cov neeg ua suab paj nruag twb tawm mus lawm tab sis cov ntawv suab paj nruag tseem nyob ntawd, qhov ntawd tsuas yog suab nrov xwb.

Tshem tawm cov haujlwm CRON tsis raug cai yuav ntxuav cov suab nrov no, ua kom lub kaw lus khiav ntawm qhov nrawm huv.

Hauv lub hnub nyoog digital, kev ua haujlwm tau zoo yog lub neej.

Kev ua tau zoo ntawm lub vev xaib tsis yog nyob ntawm nws cov teebmeem zoo nkauj pem hauv ntej xwb, tab sis kuj nyob ntawm nws txoj kev tswj hwm tom qab.

Kev paub txog cov lej no yuav muab lub peev xwm rau WordPress los kho koj tus kheej.

Raws li Hegel tau hais ib zaug, "Kev ywj pheej tsis yog ua txhua yam koj xav tau, tab sis kev tswj tus kheej."

Tsuas yog los ntawm kev qhia koj WordPress kom tswj tus kheej xwb koj thiaj li tso tau lub hwj chim ntawm kev ywj pheej tiag tiag.

评论 评论

Koj email chaw nyob yuav tsis raug luam tawm. Yuav tsum tau siv cov liaj teb * Ntaus Cim

Tsab ntawv teev npe
Scroll rau saum