WP cron 이벤트가 발생하지만 디버깅에서 중단점에 도달하지 않음
알 수 없는 문제가 있어요.커스텀 WP cron 스케줄과 그 스케줄로 WP cron 이벤트를 설정했습니다.디버깅에 PHPStorm을 사용하고 있으며 check_mail() 훅 내부에 브레이크 포인트를 설정했습니다.중단점은 히트하지 않지만 로그 파일("Got to check_mail()!")의 엔트리를 볼 수 있기 때문에 check_mail() 내의 코드가 실행됩니다.
다른 모든 중단점은 정상적으로 동작하며 check_mail() 루틴에는 로그 쓰기 및 반환이라는 두 줄의 코드만 포함되어 있습니다.
코드가 실행되는데 브레이크포인트가 안 맞아서 어떻게 이런 일이 일어날까요?
컨스트럭터:
add_action( 'check_mail', array($this, 'check_mail' ), 10, 0);
if ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) {
add_action( 'init', array( $this, 'schedule_wp_cron' ), 10, 0 );
}
지원 루틴:
public function schedule_wp_cron()
{
/**
* Avoid rescheduling cron if it's already scheduled.
*/
$args = array( );
if ( !wp_next_scheduled( 'check_mail' )) {
/**
* Schedule mail server polling.
*/
wp_schedule_event( time(), 'custom_interval', 'check_mail');
}
}
public function check_mail( )
{
// **BREAKPOINT SET ON NEXT LINE**
write_log( 'emails', 'Got to check_mail()!' );
//... do something ...
return;
}
public function custom_cron_schedule( $schedules )
{
$schedules[ 'custom_interval' ] = array(
'interval' => 300,
'display' => 'Custom Interval',
);
return $schedules;
}
WP Cron 태스크는 리모트 POST 요구에 의해 별도의 프로세스로 실행됩니다.요청에 debug session start 파라미터가 없기 때문에 PhpStrom은 코드에 설정된 중단점에서 중지되지 않습니다.
여기 해결책이 있습니다.필터는 모든 WP Cron 요청에 추가 파라미터를 추가합니다.XDEBUG_SESSION_START 값을 기본값으로 대체하고 아래 코드를 플러그인 또는 테마 코드에 추가합니다.크론 태스크에서도 PhpStorm은 중단점에서 정지합니다.
add_filter( 'cron_request', 'wp_cron_debug', 10, 2 );
function wp_cron_debug( $args, $doing_cron ) {
$args['url'] = add_query_arg( array(
'XDEBUG_SESSION_START' => 'PHPSTORM' // <== replace PHPSTORM with your key
), $args['url'] );
return $args;
}
도움이 됐으면 좋겠다!
파벨의 대답은 나에게 마법처럼 작용했고 나는 이것에 대한 답을 며칠 동안 찾고 있었다.
하지만 생각할수록 더 일반적인 해결책이 필요했어요특정 IDE 키를 하드코드로 만들 필요가 없었습니다.
제가 생각해낸 건 다음과 같습니다.
add_action ('cron_request', 'so_add_cron_xdebug_cookie', 10, 2) ;
/**
* Allow debugging of wp_cron jobs
*
* @param array $cron_request_array
* @param string $doing_wp_cron
*
* @return array $cron_request_array with the current XDEBUG_SESSION cookie added if set
*/
function
so_add_cron_xdebug_cookie ($cron_request_array, $doing_wp_cron)
{
if (empty ($_COOKIE['XDEBUG_SESSION'])) {
return ($cron_request_array) ;
}
if (empty ($cron_request_array['args']['cookies'])) {
$cron_request_array['args']['cookies'] = array () ;
}
$cron_request_array['args']['cookies']['XDEBUG_SESSION'] = $_COOKIE['XDEBUG_SESSION'] ;
return ($cron_request_array) ;
}
언급URL : https://stackoverflow.com/questions/41047039/wp-cron-event-firing-but-doesnt-hit-breakpoint-in-debug
'programing' 카테고리의 다른 글
Oracle에서 기본 키 열을 얻는 방법 (0) | 2023.03.31 |
---|---|
React.js: 페이지 맨 위로 스크롤하는 것을 중지합니다. (0) | 2023.03.31 |
wordpress에서 querystring 매개 변수 값을 가져오는 중 (0) | 2023.03.31 |
각도를 수동으로 트리거하는 방법폼 태그 외부에 있는 버튼에서 JS 유효성 검사를 수행하시겠습니까? (0) | 2023.03.31 |
Python의 문자열에서 사전으로 (0) | 2023.03.31 |