Title: Cron function not being hit
Last modified: September 5, 2018

---

# Cron function not being hit

 *  Resolved [mikelast](https://wordpress.org/support/users/mikelast/)
 * (@mikelast)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/cron-function-not-being-hit/)
 * 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](https://wordpress.org/support/users/mikelast/)
 * (@mikelast)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/cron-function-not-being-hit/#post-10658500)
 * 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](https://wordpress.org/support/users/johnbillion/)
 * (@johnbillion)
 * WordPress Core Developer
 * [7 years, 9 months ago](https://wordpress.org/support/topic/cron-function-not-being-hit/#post-10659384)
 * 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](https://wordpress.org/support/users/mikelast/)
 * (@mikelast)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/cron-function-not-being-hit/#post-10659427)
 * 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](https://wordpress.org/support/users/johnbillion/)
 * (@johnbillion)
 * WordPress Core Developer
 * [7 years, 9 months ago](https://wordpress.org/support/topic/cron-function-not-being-hit/#post-10659459)
 * 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.

 * ![](https://ps.w.org/wp-crontrol/assets/icon.svg?rev=3539529)
 * [WP Crontrol](https://wordpress.org/plugins/wp-crontrol/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-crontrol/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-crontrol/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-crontrol/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-crontrol/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-crontrol/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [John Blackbourn](https://wordpress.org/support/users/johnbillion/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/cron-function-not-being-hit/#post-10659459)
 * Status: resolved