2012-09-13 2 views
4

wp-includes에서 cron.php 코드를 읽고 spawn_cron()이 실제로 등록 된 작업을 실행하는 것으로 보입니다.WordPress Cron API는 백그라운드에서 실행됩니까?

함수의 마지막 두 줄은 :

$cron_url = site_url('wp-cron.php?doing_wp_cron=' . $doing_wp_cron); 

wp_remote_post($cron_url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true))); 

그것은 단순히 쿼리 인수로 작업에게 전달 WP-cron.php를 엽니 다.

cron.php의 상단에있는 API에 대한 설명 :

* Schedules a hook which will be executed once by the WordPress actions core at 
* a time which you specify. The action will fire off when someone visits your 
* WordPress site, if the schedule time has passed.` 

내 질문에 그의는 방문자가 다음 사이트의 페이지 중 하나 등록 작업이 크론에 의해 해고를 엽니 다라고 할 수있다 API. 그리고 작업이 무거워서 완료하는 데 몇 분이 걸리는 경우 방문자는 작업이 끝날 때까지 완전히로드되지 않은 페이지를 가져 옵니까?

[편집] 내가 묻는 바를 명확히하기 위해 WP Cron API는 페이지로드가 완료된 후에 작업을 실행합니까?

답변

2
$cron_url = site_url('wp-cron.php?doing_wp_cron=' . $doing_wp_cron); 
wp_remote_post($cron_url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true))); 

위의 샘플 플러그인을 사용하여 위 코드 (실제로 질문에서 인용 함)가 실제로 예약 된 작업을 호출한다는 것을 확인했습니다. 0.0.1 시간 제한을 설정하고 wp-cron.php에 액세스합니다. 즉, 100 개의 작업이있는 경우 모든 작업을로드하는 데 1 초가 걸립니다. 따라서 페이지 로딩 속도에 약간의 영향을 미칩니다. 그러나 그것은 너무 많이 걱정하지 않는 것 같다.

<?php 
/* Plugin Name: Sample Cron Task */ 

    // I used `heavy` because this code was initially written to test how it affects the server response if a heavy task is registered as a cron job. So forget about the naming. 
add_action('admin_menu', 'sample_cron_heavy_task'); 
function sample_cron_heavy_task() { 
    add_options_page(
     'Sample Cron Heavy Task', 
     'Sample Cron Heavy Task', 
     'manage_options', 
     'sample_cron_heavy_task', 
     'sample_cron_heavy_task_admin'); 
} 
function sample_cron_heavy_task_admin() { 
    ?> 
    <div class="wrap"> 
    <?php 
     wp_schedule_single_event(time(), 'my_action_name'); 
     $cron_url = site_url('wp-cron.php?doing_wp_cron=' . $doing_wp_cron); 
     // executes the registered task immediately 
     wp_remote_post($cron_url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true))); 
     echo get_option('sample_cron_heavy_task'); 
    ?> 
    </div> 
    <?php 
} 

add_action('my_action_name', 'myevent'); 
function myevent() { 
    $msg = date('Y m d h:i:s A') . ': the cron task is called.<br />'; 
    update_option('sample_cron_heavy_task', $msg); 
} 
+1

방문자는 작업이 끝날 때까지 완전히로드되지 않은 페이지를 가져 옵니까? – EmptyData

-1

크론 작업은 뷰어에 전혀 영향을 미치지 않습니다. 새로운 호스팅 회사를 찾으면.

+0

무슨 뜻인지 확실치 않습니다. – Teno

+0

기능이 제대로 설정되어 있으면 페이지를 만드는 데 필요한 데이터를 받아야합니다. 데이터베이스 검색에서 일시 중지가 없어야합니다. – James

+2

나는 네가하는 말을 얻기가 힘들다. '새로운 호스팅 업체를 찾았다면''페이지를 만들다''데이터베이스에서 검색하기''와 같은 질문은 관련성이 없다. 내가 놓친 게 있니? – Teno

관련 문제