Skip to content

PHP-194 - Make the scan timeout configurable. #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
63 changes: 41 additions & 22 deletions src/wpephpcompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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' );
Expand Down