Skip to content

Commit baaf250

Browse files
authored
Merge pull request #39 from octalmage/PHP-194
PHP-194 - Make the scan timeout configurable.
2 parents 4bafcd4 + 79885f3 commit baaf250

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ Example: `wp phpcompat 5.5 --scan=active`
8585

8686
5. Why was my plugin/theme skipped?
8787

88-
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.
88+
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.
89+
90+
You can use the filter `wpephpcompat_scan_timeout` to customize the scan timeout. See [this](https://gist.github.com/octalmage/07f26e0d1f25cea9a8ca92ebc67a3a14) for an example.
91+
92+
Setting the timeout to 0 disables the cron/timeout.
8993

9094
6. I found a bug, or have a suggestion, can I contribute back?
9195

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ Example: `wp phpcompat 5.5 --scan=active`
8585

8686
5. Why was my plugin/theme skipped?
8787

88-
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.
88+
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.
89+
90+
You can use the filter `wpephpcompat_scan_timeout` to customize the scan timeout. See [this](https://gist.github.com/octalmage/07f26e0d1f25cea9a8ca92ebc67a3a14) for an example.
91+
92+
Setting the timeout to 0 disables the cron/timeout.
8993

9094
6. I found a bug, or have a suggestion, can I contribute back?
9195

src/wpephpcompat.php

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,45 @@ function __construct( $dir ) {
8888
public function start_test() {
8989

9090
$this->debug_log( 'startScan: ' . isset( $_POST['startScan'] ) );
91-
// Try to lock.
92-
$lock_result = add_option( 'wpephpcompat.lock', time(), '', 'no' );
93-
94-
$this->debug_log( 'lock: ' . $lock_result );
95-
96-
if ( ! $lock_result ) {
97-
$lock_result = get_option( 'wpephpcompat.lock' );
98-
99-
// Bail if we were unable to create a lock, or if the existing lock is still valid.
100-
if ( ! $lock_result || ( $lock_result > ( time() - MINUTE_IN_SECONDS ) ) ) {
101-
$this->debug_log( 'Process already running (locked), returning.' );
102-
103-
$timestamp = wp_next_scheduled( 'wpephpcompat_start_test_cron' );
104-
105-
if ( $timestamp == false ) {
106-
wp_schedule_single_event( time() + ( MINUTE_IN_SECONDS ), 'wpephpcompat_start_test_cron' );
91+
92+
/**
93+
* Filters the scan timeout.
94+
*
95+
* Lets you change the timeout of the scan. The value is how long the scan
96+
* runs before dying and picking back up on a cron. You can set $timeout to
97+
* 0 to disable the timeout and the cron.
98+
*
99+
* @since 1.0.4
100+
*
101+
* @param int $timeout The timeout in seconds.
102+
*/
103+
$timeout = apply_filters( 'wpephpcompat_scan_timeout', MINUTE_IN_SECONDS );
104+
$this->debug_log( 'timeout: ' . $timeout );
105+
106+
// No reason to lock if there's no timeout.
107+
if ( 0 !== $timeout ) {
108+
// Try to lock.
109+
$lock_result = add_option( 'wpephpcompat.lock', time(), '', 'no' );
110+
111+
$this->debug_log( 'lock: ' . $lock_result );
112+
113+
if ( ! $lock_result ) {
114+
$lock_result = get_option( 'wpephpcompat.lock' );
115+
116+
// Bail if we were unable to create a lock, or if the existing lock is still valid.
117+
if ( ! $lock_result || ( $lock_result > ( time() - $timeout ) ) ) {
118+
$this->debug_log( 'Process already running (locked), returning.' );
119+
120+
$timestamp = wp_next_scheduled( 'wpephpcompat_start_test_cron' );
121+
122+
if ( $timestamp == false ) {
123+
wp_schedule_single_event( time() + $timeout, 'wpephpcompat_start_test_cron' );
124+
}
125+
return;
107126
}
108-
return;
109127
}
128+
update_option( 'wpephpcompat.lock', time(), false );
110129
}
111-
update_option( 'wpephpcompat.lock', time(), false );
112130

113131
// Check to see if scan has already started.
114132
$scan_status = get_option( 'wpephpcompat.status' );
@@ -145,15 +163,16 @@ public function start_test() {
145163

146164
return;
147165
}
148-
149-
wp_schedule_single_event( time() + ( MINUTE_IN_SECONDS ), 'wpephpcompat_start_test_cron' );
166+
if ( 0 !== $timeout ) {
167+
wp_schedule_single_event( time() + $timeout, 'wpephpcompat_start_test_cron' );
168+
}
150169

151170
if ( ! $this->is_command_line() ) {
152171
// Close the connection to the browser.
153172
$this->close_connection("started");
154173

155-
// Kill cron after a minute.
156-
set_time_limit( 55 );
174+
// Kill cron after a configurable timeout.
175+
set_time_limit( ( $timeout > 5 ? $timeout - 5 : $timeout ) );
157176
}
158177

159178
$scan_results = get_option( 'wpephpcompat.scan_results' );

0 commit comments

Comments
 (0)