88 $threads = $this->
getOption(
'threads', 1 );
89 if ( $threads < 1 || $threads != intval( $threads ) ) {
90 $this->
output(
"Invalid thread count specified; running single-threaded.\n" );
94 $this->
output(
"Threaded rebuild is not supported on Windows; running single-threaded.\n" );
97 if ( $threads > 1 && ( !extension_loaded(
'sockets' ) || !function_exists(
'pcntl_fork' ) ) ) {
98 $this->
output(
"Threaded rebuild requires ext-pcntl and ext-sockets; running single-threaded.\n" );
102 $conf = $this->
getConfig()->get( MainConfigNames::LocalisationCacheConf );
104 $conf[
'manualRecache'] =
false;
105 $conf[
'forceRecache'] = $force || !empty( $conf[
'forceRecache'] );
107 $conf[
'storeDirectory'] = $this->
getOption(
'outdir' );
110 if ( $this->
hasOption(
'store-class' ) ) {
111 $conf[
'storeClass'] = $this->
getOption(
'store-class' );
118 LocalisationCache::CONSTRUCTOR_OPTIONS,
120 $services->getMainConfig()
122 LocalisationCache::getStoreFromConf( $conf, $this->getConfig()->get( MainConfigNames::CacheDirectory ) ),
123 LoggerFactory::getInstance(
'localisation' ),
124 $this->hasOption(
'skip-message-purge' ) ? [] :
125 [
static function () use ( $services ) {
126 MessageBlobStore::clearGlobalCacheEntry( $services->getMainWANObjectCache() );
128 $services->getLanguageNameUtils(),
129 $services->getHookContainer()
132 $allCodes = array_keys( $services
133 ->getLanguageNameUtils()
134 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED ) );
136 # Validate requested languages
137 $codes = array_intersect( $allCodes,
138 explode(
',', $this->
getOption(
'lang' ) ) );
139 # Bailed out if nothing is left
140 if ( count( $codes ) == 0 ) {
141 $this->
fatalError(
'None of the languages specified exists.' );
144 # By default get all languages
150 $total = count( $codes );
153 if ( $threads <= 1 ) {
155 $numRebuilt += $this->doRebuild( $codes, $lc, $force );
158 $chunks = array_chunk( $codes, ceil( count( $codes ) / $threads ) );
162 foreach ( $chunks as $codes ) {
166 if ( !socket_create_pair( AF_UNIX, SOCK_STREAM, 0, $socketpair ) ) {
167 $this->
fatalError(
'socket_create_pair failed' );
174 } elseif ( $pid === 0 ) {
177 mt_srand( getmypid() );
179 $numRebuilt = $this->doRebuild( $codes, $lc, $force );
181 $msg =
"$numRebuilt\n";
182 socket_write( $socketpair[1], $msg, strlen( $msg ) );
187 $sockets[$pid] = $socketpair[0];
192 foreach ( $sockets as $pid => $socket ) {
194 pcntl_waitpid( $pid, $status );
196 if ( pcntl_wifexited( $status ) ) {
197 $code = pcntl_wexitstatus( $status );
199 $this->
output(
"Pid $pid exited with status $code !!\n" );
202 $res = socket_read( $socket, 512, PHP_NORMAL_READ );
203 if ( $res ===
false ) {
204 $this->
output(
"socket_read failed in parent\n" );
206 $numRebuilt += intval( $res );
211 $parentStatus |= $code;
212 } elseif ( pcntl_wifsignaled( $status ) ) {
213 $signum = pcntl_wtermsig( $status );
214 $this->
output(
"Pid $pid terminated by signal $signum !!\n" );
220 $this->
output(
"$numRebuilt languages rebuilt out of $total\n" );
221 if ( $numRebuilt === 0 ) {
222 $this->
output(
"Use --force to rebuild the caches which are still fresh.\n" );
224 if ( $parentStatus ) {
225 $this->
fatalError(
'Failed.', $parentStatus );