diff --git a/readme.md b/readme.md index 420e89b..aca0110 100644 --- a/readme.md +++ b/readme.md @@ -85,7 +85,11 @@ Example: `wp phpcompat 5.5 --scan=active` 5. Why was my plugin/theme skipped? - Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issues is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site. + Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issue is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site, or you can use the WP-CLI command. + + You can use the filter `wpephpcompat_scan_timeout` to customize the scan timeout. See [this](https://gist.github.com/octalmage/07f26e0d1f25cea9a8ca92ebc67a3a14) for an example. + + Setting the timeout to 0 disables the cron/timeout. 6. I found a bug, or have a suggestion, can I contribute back? diff --git a/readme.txt b/readme.txt index 8e723cf..7ca4e86 100644 --- a/readme.txt +++ b/readme.txt @@ -85,7 +85,11 @@ Example: `wp phpcompat 5.5 --scan=active` 5. Why was my plugin/theme skipped? - Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issues is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site. + Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issue is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site, or you can use the WP-CLI command. + + You can use the filter `wpephpcompat_scan_timeout` to customize the scan timeout. See [this](https://gist.github.com/octalmage/07f26e0d1f25cea9a8ca92ebc67a3a14) for an example. + + Setting the timeout to 0 disables the cron/timeout. 6. I found a bug, or have a suggestion, can I contribute back? diff --git a/src/wpephpcompat.php b/src/wpephpcompat.php index faaa489..db78950 100644 --- a/src/wpephpcompat.php +++ b/src/wpephpcompat.php @@ -88,27 +88,45 @@ function __construct( $dir ) { public function start_test() { $this->debug_log( 'startScan: ' . isset( $_POST['startScan'] ) ); - // Try to lock. - $lock_result = add_option( 'wpephpcompat.lock', time(), '', 'no' ); - - $this->debug_log( 'lock: ' . $lock_result ); - - if ( ! $lock_result ) { - $lock_result = get_option( 'wpephpcompat.lock' ); - - // Bail if we were unable to create a lock, or if the existing lock is still valid. - if ( ! $lock_result || ( $lock_result > ( time() - MINUTE_IN_SECONDS ) ) ) { - $this->debug_log( 'Process already running (locked), returning.' ); - - $timestamp = wp_next_scheduled( 'wpephpcompat_start_test_cron' ); - - if ( $timestamp == false ) { - wp_schedule_single_event( time() + ( MINUTE_IN_SECONDS ), 'wpephpcompat_start_test_cron' ); + + /** + * Filters the scan timeout. + * + * Lets you change the timeout of the scan. The value is how long the scan + * runs before dying and picking back up on a cron. You can set $timeout to + * 0 to disable the timeout and the cron. + * + * @since 1.0.4 + * + * @param int $timeout The timeout in seconds. + */ + $timeout = apply_filters( 'wpephpcompat_scan_timeout', MINUTE_IN_SECONDS ); + $this->debug_log( 'timeout: ' . $timeout ); + + // No reason to lock if there's no timeout. + if ( 0 !== $timeout ) { + // Try to lock. + $lock_result = add_option( 'wpephpcompat.lock', time(), '', 'no' ); + + $this->debug_log( 'lock: ' . $lock_result ); + + if ( ! $lock_result ) { + $lock_result = get_option( 'wpephpcompat.lock' ); + + // Bail if we were unable to create a lock, or if the existing lock is still valid. + if ( ! $lock_result || ( $lock_result > ( time() - $timeout ) ) ) { + $this->debug_log( 'Process already running (locked), returning.' ); + + $timestamp = wp_next_scheduled( 'wpephpcompat_start_test_cron' ); + + if ( $timestamp == false ) { + wp_schedule_single_event( time() + $timeout, 'wpephpcompat_start_test_cron' ); + } + return; } - return; } + update_option( 'wpephpcompat.lock', time(), false ); } - update_option( 'wpephpcompat.lock', time(), false ); // Check to see if scan has already started. $scan_status = get_option( 'wpephpcompat.status' ); @@ -145,15 +163,16 @@ public function start_test() { return; } - - wp_schedule_single_event( time() + ( MINUTE_IN_SECONDS ), 'wpephpcompat_start_test_cron' ); + if ( 0 !== $timeout ) { + wp_schedule_single_event( time() + $timeout, 'wpephpcompat_start_test_cron' ); + } if ( ! $this->is_command_line() ) { // Close the connection to the browser. $this->close_connection("started"); - // Kill cron after a minute. - set_time_limit( 55 ); + // Kill cron after a configurable timeout. + set_time_limit( ( $timeout > 5 ? $timeout - 5 : $timeout ) ); } $scan_results = get_option( 'wpephpcompat.scan_results' );