Step debug wp cron run – ideas how to get this working in PHPStorm with Xdebug?


This is driving me a bit nuts…

I am using my Mac’s cron functionality to run WordPress cron jobs.

In wp-config.php

I have

define('DISABLE_WP_CRON', true);
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
define( 'SCRIPT_DEBUG', false );

Not sure if define( 'WP_DEBUG', true ); plays a role in my case.

Then I created a script to run jobs, which is

export XDEBUG_CONFIG="mode=debug client_host= client_port=9003 start_with_request=yes"
cd /folder
for hook in $(wp cron event list --next_run_relative=now --fields=hook --format=ids); 
  do wp cron event run --debug "$hook";
echo "again in cron - debug set" >> /somefolder/stdout.log

I see that the cron is running as there is output to stdout.log

In my IDE (PHPStorm), I have xdebug set to port 9003, and set to break at first line.

In my xdebug log I see entries like

tail -n 500 xdebug.log
[16636] [Step Debug] <- breakpoint_set -i 17 -t line -f file:///mysite/wp-content/plugins/sfwd-lms/themes/ld30/templates/course_registered_rows.php -n 14
[16636] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="" command="breakpoint_set" transaction_id="17" id="166360004" resolved="unresolved"></response>

[16636] [Step Debug] <- breakpoint_set -i 18 -t line -f file:///mysite/wp-content/plugins/learndash-notifications/includes/cron.php -n 79
[16636] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="" command="breakpoint_set" transaction_id="18" id="166360005" resolved="unresolved"></response>

where the breakpoint lines shown in the log correspond to what I set in PHPStorm.

I can step debug everything imaginable, except this wp cron run. I have incoming webhooks from mailchimp, etc, all triggering step debugging. But with this cron, PHPStorm shows a debug step for wp, but when I hit resume none of the breakpoints in the project are tripped, even though they are set.

I feel like I am almost there. But something not quite right…


Brian 10 months 2021-10-29T10:51:37-05:00 0 Answers 0 views 0

Leave an answer