100 $threads = $this->
getOption(
'threads', 1 );
101 if ( $threads < 1 || $threads != intval( $threads ) ) {
102 $this->
output(
"Invalid thread count specified; running single-threaded.\n" );
106 $this->
output(
"Threaded rebuild is not supported on Windows; running single-threaded.\n" );
109 if ( $threads > 1 && ( !extension_loaded(
'sockets' ) || !function_exists(
'pcntl_fork' ) ) ) {
110 $this->
output(
"Threaded rebuild requires ext-pcntl and ext-sockets; running single-threaded.\n" );
114 $conf = $this->
getConfig()->get( MainConfigNames::LocalisationCacheConf );
116 $conf[
'manualRecache'] =
false;
117 $conf[
'forceRecache'] = $force || !empty( $conf[
'forceRecache'] );
119 $conf[
'storeDirectory'] = $this->
getOption(
'outdir' );
122 if ( $this->
hasOption(
'store-class' ) ) {
123 $conf[
'storeClass'] = $this->
getOption(
'store-class' );
130 LocalisationCache::CONSTRUCTOR_OPTIONS,
132 $services->getMainConfig()
134 LocalisationCache::getStoreFromConf( $conf, $this->getConfig()->get( MainConfigNames::CacheDirectory ) ),
135 LoggerFactory::getInstance(
'localisation' ),
136 $this->hasOption(
'skip-message-purge' ) ? [] :
137 [
static function () use ( $services ) {
138 MessageBlobStore::clearGlobalCacheEntry( $services->getMainWANObjectCache() );
140 $services->getLanguageNameUtils(),
141 $services->getHookContainer()
144 $allCodes = array_keys( $services
145 ->getLanguageNameUtils()
146 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED ) );
148 # Validate requested languages
149 $codes = array_intersect( $allCodes,
150 explode(
',', $this->
getOption(
'lang' ) ) );
151 # Bailed out if nothing is left
152 if ( count( $codes ) == 0 ) {
153 $this->
fatalError(
'None of the languages specified exists.' );
156 # By default get all languages
162 $total = count( $codes );
165 if ( $threads <= 1 ) {
167 $numRebuilt += $this->doRebuild( $codes, $lc, $force );
170 $chunks = array_chunk( $codes, ceil( count( $codes ) / $threads ) );
174 foreach ( $chunks as $codes ) {
178 if ( !socket_create_pair( AF_UNIX, SOCK_STREAM, 0, $socketpair ) ) {
179 $this->
fatalError(
'socket_create_pair failed' );
186 } elseif ( $pid === 0 ) {
189 mt_srand( getmypid() );
191 $numRebuilt = $this->doRebuild( $codes, $lc, $force );
193 $msg =
"$numRebuilt\n";
194 socket_write( $socketpair[1], $msg, strlen( $msg ) );
199 $sockets[$pid] = $socketpair[0];
204 foreach ( $sockets as $pid => $socket ) {
206 pcntl_waitpid( $pid, $status );
208 if ( pcntl_wifexited( $status ) ) {
209 $code = pcntl_wexitstatus( $status );
211 $this->
output(
"Pid $pid exited with status $code !!\n" );
214 $res = socket_read( $socket, 512, PHP_NORMAL_READ );
215 if ( $res ===
false ) {
216 $this->
output(
"socket_read failed in parent\n" );
218 $numRebuilt += intval( $res );
223 $parentStatus |= $code;
224 } elseif ( pcntl_wifsignaled( $status ) ) {
225 $signum = pcntl_wtermsig( $status );
226 $this->
output(
"Pid $pid terminated by signal $signum !!\n" );
232 $this->
output(
"$numRebuilt languages rebuilt out of $total\n" );
233 if ( $numRebuilt === 0 ) {
234 $this->
output(
"Use --force to rebuild the caches which are still fresh.\n" );
236 if ( $parentStatus ) {
237 $this->
fatalError(
'Failed.', $parentStatus );