86 $threads = $this->
getOption(
'threads', 1 );
87 if ( $threads < 1 || $threads != intval( $threads ) ) {
88 $this->
output(
"Invalid thread count specified; running single-threaded.\n" );
92 $this->
output(
"Threaded rebuild is not supported on Windows; running single-threaded.\n" );
95 if ( $threads > 1 && ( !extension_loaded(
'sockets' ) || !function_exists(
'pcntl_fork' ) ) ) {
96 $this->
output(
"Threaded rebuild requires ext-pcntl and ext-sockets; running single-threaded.\n" );
100 $conf = $this->
getConfig()->get( MainConfigNames::LocalisationCacheConf );
102 $conf[
'manualRecache'] =
false;
103 $conf[
'forceRecache'] = $force || !empty( $conf[
'forceRecache'] );
105 $conf[
'storeDirectory'] = $this->
getOption(
'outdir' );
108 if ( $this->
hasOption(
'store-class' ) ) {
109 $conf[
'storeClass'] = $this->
getOption(
'store-class' );
116 LocalisationCache::CONSTRUCTOR_OPTIONS,
118 $services->getMainConfig()
120 LocalisationCache::getStoreFromConf( $conf, $this->getConfig()->get( MainConfigNames::CacheDirectory ) ),
121 LoggerFactory::getInstance(
'localisation' ),
122 $this->hasOption(
'skip-message-purge' ) ? [] :
123 [
static function () use ( $services ) {
124 MessageBlobStore::clearGlobalCacheEntry( $services->getMainWANObjectCache() );
126 $services->getLanguageNameUtils(),
127 $services->getHookContainer()
130 $allCodes = array_keys( $services
131 ->getLanguageNameUtils()
132 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED ) );
134 # Validate requested languages
135 $codes = array_intersect( $allCodes,
136 explode(
',', $this->
getOption(
'lang' ) ) );
137 # Bailed out if nothing is left
138 if ( count( $codes ) == 0 ) {
139 $this->
fatalError(
'None of the languages specified exists.' );
142 # By default get all languages
148 $total = count( $codes );
151 if ( $threads <= 1 ) {
153 $numRebuilt += $this->doRebuild( $codes, $lc, $force );
156 $chunks = array_chunk( $codes, ceil( count( $codes ) / $threads ) );
160 foreach ( $chunks as $codes ) {
164 if ( !socket_create_pair( AF_UNIX, SOCK_STREAM, 0, $socketpair ) ) {
165 $this->
fatalError(
'socket_create_pair failed' );
172 } elseif ( $pid === 0 ) {
175 mt_srand( getmypid() );
177 $numRebuilt = $this->doRebuild( $codes, $lc, $force );
179 $msg =
"$numRebuilt\n";
180 socket_write( $socketpair[1], $msg, strlen( $msg ) );
185 $sockets[$pid] = $socketpair[0];
190 foreach ( $sockets as $pid => $socket ) {
192 pcntl_waitpid( $pid, $status );
194 if ( pcntl_wifexited( $status ) ) {
195 $code = pcntl_wexitstatus( $status );
197 $this->
output(
"Pid $pid exited with status $code !!\n" );
200 $res = socket_read( $socket, 512, PHP_NORMAL_READ );
201 if ( $res ===
false ) {
202 $this->
output(
"socket_read failed in parent\n" );
204 $numRebuilt += intval( $res );
209 $parentStatus |= $code;
210 } elseif ( pcntl_wifsignaled( $status ) ) {
211 $signum = pcntl_wtermsig( $status );
212 $this->
output(
"Pid $pid terminated by signal $signum !!\n" );
218 $this->
output(
"$numRebuilt languages rebuilt out of $total\n" );
219 if ( $numRebuilt === 0 ) {
220 $this->
output(
"Use --force to rebuild the caches which are still fresh.\n" );
222 if ( $parentStatus ) {
223 $this->
fatalError(
'Failed.', $parentStatus );