• Hi,

    Trying to figure out how to get my cron jobs to trigger breakpoints in PHPStorm via Xdebug 3.

    I have some details here:

    https://wordpress.stackexchange.com/questions/397491/step-debug-wp-cron-run-ideas-how-to-get-this-working-in-phpstorm-with-xdebug

    To repeat what is there:

    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

    #!/bin/bash
    #!/bin/bash
    clear
    export XDEBUG_CONFIG=”mode=debug client_host=127.0.0.1 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”;
    done;
    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=”https://xdebug.org/dbgp/xdebug&#8221; 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=”https://xdebug.org/dbgp/xdebug&#8221; 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…

    Ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Alan Fuller

    (@alanfuller)

    You know, I more than often just ‘cheat’ and whilst debugging add an extra hook on init to run the cron function, set a breakpoint and hit refresh.

    I also have had some success using the CRONTROL plugin to manually kick off crons and getting PHPstorm to pick up the breaks.

    Shlomi

    (@shlomimendelics)

    @huetherb – See if this helps ya – https://stackoverflow.com/questions/41047039/wp-cron-event-firing-but-doesnt-hit-breakpoint-in-debug

    @alanfuller – your xDebug really manage to stop on wp-crons breakpoints, just by running them manually via control? You have not made any config to enable that?

    • This reply was modified 2 years, 9 months ago by Shlomi.

    Yes it does – but I never use IDE keys when debugging from localhost docker containers, I take all connections. Maybe it is simply an IDE key issue for the OP

    Shlomi

    (@shlomimendelics)

    @alanfuller How do you manage to breakpoint inside the jobs, while they run outside of the current process?
    For me I am unable to break inside the jobs.. my xDebug is totally blind to them (and work well with the key. Is that a bad practice in your opinion?)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to step debug wp cron run with xdebug?’ is closed to new replies.