97 $threads = $this->
getOption(
'threads', 1 );
98 if ( $threads < 1 || $threads != intval( $threads ) ) {
99 $this->
output(
"Invalid thread count specified; running single-threaded.\n" );
103 $this->
output(
"Threaded rebuild is not supported on Windows; running single-threaded.\n" );
106 if ( $threads > 1 && ( !extension_loaded(
'sockets' ) || !function_exists(
'pcntl_fork' ) ) ) {
107 $this->
output(
"Threaded rebuild requires ext-pcntl and ext-sockets; running single-threaded.\n" );
111 $conf = $this->
getConfig()->get( MainConfigNames::LocalisationCacheConf );
113 $conf[
'manualRecache'] =
false;
114 $conf[
'forceRecache'] = $force || !empty( $conf[
'forceRecache'] );
116 $conf[
'storeDirectory'] = $this->
getOption(
'outdir' );
119 if ( $this->
hasOption(
'store-class' ) ) {
120 $conf[
'storeClass'] = $this->
getOption(
'store-class' );
127 LocalisationCache::CONSTRUCTOR_OPTIONS,
129 $services->getMainConfig()
131 LocalisationCache::getStoreFromConf( $conf, $this->getConfig()->get( MainConfigNames::CacheDirectory ) ),
132 LoggerFactory::getInstance(
'localisation' ),
133 $this->hasOption(
'skip-message-purge' ) ? [] :
134 [
static function () use ( $services ) {
135 MessageBlobStore::clearGlobalCacheEntry( $services->getMainWANObjectCache() );
137 $services->getLanguageNameUtils(),
138 $services->getHookContainer()
141 $allCodes = array_keys( $services
142 ->getLanguageNameUtils()
143 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED ) );
145 # Validate requested languages
146 $codes = array_intersect( $allCodes,
147 explode(
',', $this->
getOption(
'lang' ) ) );
148 # Bailed out if nothing is left
149 if ( count( $codes ) == 0 ) {
150 $this->
fatalError(
'None of the languages specified exists.' );
153 # By default get all languages
159 $total = count( $codes );
162 if ( $threads <= 1 ) {
164 $numRebuilt += $this->doRebuild( $codes, $lc, $force );
167 $chunks = array_chunk( $codes, ceil( count( $codes ) / $threads ) );
171 foreach ( $chunks as $codes ) {
175 if ( !socket_create_pair( AF_UNIX, SOCK_STREAM, 0, $socketpair ) ) {
176 $this->
fatalError(
'socket_create_pair failed' );
183 } elseif ( $pid === 0 ) {
186 mt_srand( getmypid() );
188 $numRebuilt = $this->doRebuild( $codes, $lc, $force );
190 $msg =
"$numRebuilt\n";
191 socket_write( $socketpair[1], $msg, strlen( $msg ) );
196 $sockets[$pid] = $socketpair[0];
201 foreach ( $sockets as $pid => $socket ) {
203 pcntl_waitpid( $pid, $status );
205 if ( pcntl_wifexited( $status ) ) {
206 $code = pcntl_wexitstatus( $status );
208 $this->
output(
"Pid $pid exited with status $code !!\n" );
211 $res = socket_read( $socket, 512, PHP_NORMAL_READ );
212 if ( $res ===
false ) {
213 $this->
output(
"socket_read failed in parent\n" );
215 $numRebuilt += intval( $res );
220 $parentStatus |= $code;
221 } elseif ( pcntl_wifsignaled( $status ) ) {
222 $signum = pcntl_wtermsig( $status );
223 $this->
output(
"Pid $pid terminated by signal $signum !!\n" );
229 $this->
output(
"$numRebuilt languages rebuilt out of $total\n" );
230 if ( $numRebuilt === 0 ) {
231 $this->
output(
"Use --force to rebuild the caches which are still fresh.\n" );
233 if ( $parentStatus ) {
234 $this->
fatalError(
'Failed.', $parentStatus );