Skip to content

Commit 9d8c59a

Browse files
committed
Allow the scan timeout to be filtered.
1 parent b8e781c commit 9d8c59a

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

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)