v2.2.2
This commit is contained in:
parent
0ece5f3a6d
commit
1e78bb1378
8 changed files with 181 additions and 22 deletions
33
worker.php
33
worker.php
|
|
@ -8,9 +8,11 @@
|
|||
* This script runs as a standalone CLI process, independent of WordPress cron.
|
||||
* It loads WordPress with DOING_CRON defined to prevent triggering actual cron.
|
||||
*
|
||||
* Usage: php worker.php <batch_size> <worker_id>
|
||||
* Usage: php worker.php <batch_size> <worker_id> [--url=<site_url>]
|
||||
* Example: php worker.php 10 "w1"
|
||||
* MultiSite: php worker.php 10 "w1" --url="https://example.com"
|
||||
* Parallel: seq 1 10 | xargs -P10 -I{} php worker.php 10 "w{}"
|
||||
* Parallel MultiSite: seq 1 10 | xargs -P10 -I{} php worker.php 10 "w{}" --url="https://example.com"
|
||||
*
|
||||
* @package ROBOTSTXT_SMTP_Newsletter
|
||||
* @since 2.2.0
|
||||
|
|
@ -24,14 +26,41 @@ if ( php_sapi_name() !== 'cli' ) {
|
|||
|
||||
// Parse command-line arguments.
|
||||
if ( $argc < 3 ) {
|
||||
fwrite( STDERR, "Usage: php worker.php <batch_size> <worker_id>\n" );
|
||||
fwrite( STDERR, "Usage: php worker.php <batch_size> <worker_id> [--url=<site_url>]\n" );
|
||||
fwrite( STDERR, "Example: php worker.php 10 \"w1\"\n" );
|
||||
fwrite( STDERR, "MultiSite: php worker.php 10 \"w1\" --url=\"https://example.com\"\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
$batch_size = max( 1, (int) $argv[1] );
|
||||
$worker_id = $argv[2];
|
||||
|
||||
// Parse optional --url parameter for MultiSite support.
|
||||
$site_url = null;
|
||||
for ( $i = 3; $i < $argc; $i++ ) {
|
||||
if ( strpos( $argv[ $i ], '--url=' ) === 0 ) {
|
||||
$site_url = substr( $argv[ $i ], 6 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If --url is provided, set HTTP_HOST for WordPress to load the correct site.
|
||||
if ( $site_url ) {
|
||||
$parsed_url = parse_url( $site_url );
|
||||
if ( isset( $parsed_url['host'] ) ) {
|
||||
$_SERVER['HTTP_HOST'] = $parsed_url['host'];
|
||||
$_SERVER['SERVER_NAME'] = $parsed_url['host'];
|
||||
|
||||
// Set HTTPS if URL uses https.
|
||||
if ( isset( $parsed_url['scheme'] ) && 'https' === $parsed_url['scheme'] ) {
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
}
|
||||
|
||||
// Set REQUEST_URI to root.
|
||||
$_SERVER['REQUEST_URI'] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Load WordPress.
|
||||
define( 'DOING_CRON', true );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue