• Resolved mikelast

    (@mikelast)


    I’ve created another CRON, I have several all ready in place, this new one is not being hit, I have added breakpoints to the function but they are never hit, although in the browser it reports that the cron ran successfully when I use the run now feature. I have also tried adding wp_die() to see if maybe it was just my break points not being registered or something and the code never dies.

    Any ideas here, how can I go about debugging this to see where the problem is

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mikelast

    (@mikelast)

    Further to this, I adjusted a debug setting so that we break on the first line of php hit, the wordpress admin area then output the following error

    You are not allowed to run cron events.

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Cron events are fired asynchronously, so you won’t see any effect of a call to die() in a cron event callback function. In addition, if your Xdebug breakpoint is only triggered via an HTTP header in your browser, then it won’t trigger when called via the asynchronous server side call. You’ll need to enable auto starting, which I think is the xdebug.remote_autostart directive in your PHP config.

    You’ll need to check your hook names and callback function names, make sure they’re all correct. Beyond that, you might be better off asking in the main support forums as I don’t think this is an issue related to WP Crontrol.

    Thread Starter mikelast

    (@mikelast)

    I have managed to solve my issue. I add code and comments below in case anyone finds this post an the answers/code below help them.

    First John, thanks for coming back to me and you’re right it was not an issue relating to your plugin.

    For the xdebug thing, I added this below, so that I could be sure my breakpoints would be hit. This adds a query arguement to the URL

    add_filter( 'cron_request', 'wp_cron_debug', 10 );
    function wp_cron_debug( $args ) {
    
    	$args['url'] = add_query_arg( array(
    		'XDEBUG_SESSION_START' => 'PHPSTORM' // <== replace PHPSTORM with your key
    	), $args['url'] );
    
    	return $args;
    
    }

    This was not helpful, nothing really happened as a result of doing the above so I carried on trying to figure out what was happening. Debugging through the WP Crontrol plugin I noticed that the cron_request timeout was really low, something like 0.001, so after some further googling I discovered some actions + filters that allow me to adjust the length of the curl request process.

    
    add_action('http_api_curl', 'custom_curl_timeout', 9999, 1);
    function custom_curl_timeout( $handle ){
    	curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 10 ); // 30 seconds. Too much for production, only for testing.
    	curl_setopt( $handle, CURLOPT_TIMEOUT, 10 ); // 30 seconds. Too much for production, only for testing.
    }

    // Setting custom timeout for the HTTP request

    
    add_filter( 'http_request_timeout', 'custom_http_request_timeout', 9999 );
    function custom_http_request_timeout( $timeout_value ) {
    	return 10; // 30 seconds. Too much for production, only for testing.
    }

    // Setting custom timeout in HTTP request args

    
    add_filter('http_request_args', 'custom_http_request_args', 9999, 1);
    function custom_http_request_args( $r ){
    	$r['timeout'] = 10; // 30 seconds. Too much for production, only for testing.
    	return $r;
    }

    Finally my breakpoints were being hit

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Cheers, that sounds like a bug in WordPress core that I’ve seen crop up now and then. Certain configurations of curl will close a connection before it’s complete if the timeout is below 1 second. I’ll see if I can find some time to dig into it, but no promises ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Cron function not being hit’ is closed to new replies.