Skip to content

Commit 9278e7f

Browse files
authored
Merge pull request #46 from octalmage/fork
Make an Ajax call to fork the process.
2 parents 27926a3 + 989ff65 commit 9278e7f

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

src/js/run.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ function checkStatus() {
102102
jQuery( '#wpe-progress' ).show();
103103

104104
// Display the current plugin count.
105-
jQuery( '#wpe-progress-count' ).text( ( obj.total - obj.count + 1 ) + '/' + obj.total );
105+
if ( obj.total ) {
106+
jQuery( '#wpe-progress-count' ).text( ( obj.total - obj.count + 1 ) + '/' + obj.total );
107+
}
106108

107109
// Display the object being scanned.
108110
jQuery( '#wpe-progress-active' ).text( obj.activeJob );

src/wpephpcompat.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ public function start_test() {
188188
}
189189

190190
if ( ! $this->is_command_line() ) {
191-
// Close the connection to the browser.
192-
$this->close_connection( 'started' );
193-
194191
/**
195192
* Kill cron after a configurable timeout.
196193
* Subtract 5 from the timeout if we can to avoid race conditions.
@@ -479,29 +476,4 @@ private function debug_log( $message ) {
479476
private function is_command_line() {
480477
return defined( 'WP_CLI' ) || defined( 'PHPUNIT_TEST' ) || php_sapi_name() == 'cli';
481478
}
482-
483-
/**
484-
* Close the connection to the browser but continue processing the operation.
485-
* @since 1.0.0
486-
* @param string $body The message to send to the client.
487-
* @return null
488-
*/
489-
private function close_connection( $body ) {
490-
ignore_user_abort( true );
491-
if ( ob_get_length() ) { ob_end_clean(); }
492-
// Start buffering.
493-
ob_start();
494-
// Echo our response.
495-
echo $body;
496-
// Get the length of the buffer.
497-
$size = ob_get_length();
498-
// Close the connection.
499-
header( 'Connection: close\r\n' );
500-
header( 'Content-Encoding: none\r\n' );
501-
header( 'Content-Length: $size' );
502-
// Flush and close the buffer.
503-
ob_end_flush();
504-
// Flush the system output buffer.
505-
flush();
506-
}
507479
}

wpengine-phpcompat.php

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,26 @@ function start_test() {
9494

9595
$wpephpc = new \WPEPHPCompat( __DIR__ );
9696

97+
foreach ( array( 'test_version', 'only_active' ) as $key ) {
98+
if ( isset( $_POST[ $key ] ) ) {
99+
$$key = sanitize_text_field( $_POST[ $key ] );
100+
}
101+
}
102+
103+
// New scan!
97104
if ( isset( $_POST['startScan'] ) ) {
98-
$test_version = sanitize_text_field( $_POST['test_version'] );
99-
$only_active = sanitize_text_field( $_POST['only_active'] );
105+
// Make sure we clean up after the last test.
106+
$wpephpc->clean_after_scan();
100107

108+
// Fork so we can close the connection.
109+
$this->fork_scan( $test_version, $only_active );
110+
} else {
101111
$wpephpc->test_version = $test_version;
102112
$wpephpc->only_active = $only_active;
103-
$wpephpc->clean_after_scan();
113+
114+
$wpephpc->start_test();
104115
}
105116

106-
$wpephpc->start_test();
107117
wp_die();
108118
}
109119
}
@@ -162,6 +172,40 @@ function check_status() {
162172
}
163173
}
164174

175+
/**
176+
* Make an Ajax call to start the scan in the background.
177+
*
178+
* @since 1.3.2
179+
* @param string $test_version Version of PHP to test.
180+
* @param string $only_active Scan only active plugins or all?
181+
* @return null
182+
*/
183+
function fork_scan( $test_version, $only_active ) {
184+
$query = array(
185+
'action' => 'wpephpcompat_start_test',
186+
);
187+
188+
// Keep track of these variables.
189+
$body = array(
190+
'test_version' => $test_version,
191+
'only_active' => $only_active,
192+
);
193+
194+
// Instantly return!
195+
$args = array(
196+
'timeout' => 0.01,
197+
'blocking' => false,
198+
'body' => $body,
199+
'cookies' => $_COOKIE,
200+
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
201+
);
202+
203+
// Build our URL.
204+
$url = add_query_arg( $query, admin_url( 'admin-ajax.php' ) );
205+
// POST.
206+
wp_remote_post( esc_url_raw( $url ), $args );
207+
}
208+
165209
/**
166210
* Remove all database options from the database.
167211
*

0 commit comments

Comments
 (0)